Linux with Operating System Concepts



Download 5,65 Mb.
Pdf ko'rish
bet118/254
Sana22.07.2022
Hajmi5,65 Mb.
#840170
1   ...   114   115   116   117   118   119   120   121   ...   254
Bog'liq
Linux-with-Operating-System-Concepts-Fox-Richard-CRC-Press-2014

Amount Available
Response
100–61%
No need for any action
60–41%
Keep an eye on the system
40–26%
Delete unnecessary software
25–16%
Implement disk quotas on all users
15–6%
Add a new disk drive
5–0%
Panic


310

Linux with Operating System Concepts
For instance, if 
diskcheck –r
returns 127713651 and 
diskcheck –a
returns 
1000000000, then the program should output 12%, Add a new disk drive.
43. Revise the calculator program (that uses the if-then-elif-else clauses) to add the oper-
ations ** (exponent), 
<<
(left shift), and 
>>
(right shift). Since **, 

and 

can all be 
interpreted by the interpreter as Bash wildcards or redirection, you need to use some 
other symbol(s) for the parameters.
44. Explain why you would not want to rewrite the SCORE/GRADE if-then-elif-else 
statements from Section 7.4.4 using a case statement.
45. Rewrite the “favorite color” case statement from Section 7.4.5 using an if-then-elif-
else statement.
46. If the variable FOO has a value, we want to output it. Write such a statement using the 
[ condition ] &&/|| action syntax.
47. Redo #46 to set FOO to 1 if it currently has no value.
48. Write a while loop which will input numbers from the user until they enter 0 and 
count and output the number of times they enter the number 100.
49. Redo #48 where the user supplies a parameter to the script and the number that 
they pass will be the number you count. For instance, if this script is called as 
.
/ count.sh 50
then the script will count the number of times the input numbers 
equal 50.
For questions 50–53, assume X
=
5 and Y
=
10. How many times will each loop iterate?
50. while [ $X –lt $Y ]; do ((X
++
)); done
51. while [ $X –gt $Y ]; do ((X
++
)); done
52. while [ $X –lt $Y ]; do ((X
++
)); ((Y
++
)); done
53. while [ $X –lt $Y ]; do ((X
++
)); ((Y
−−
)); done
54. Rewrite the following iterator for loop as a counter for loop.
for num in (1 2 3 4 5); do . . . done
55. Rewrite the following iterator for loop as a counter for loop.
for num in (‘seq 5 3 15‘); do . . . done
56. Rewrite the following counter for loop to count downward instead of upward.
for ((i = 0;i < n;i++)); do . . . done
57. Write a script which will receive a list of parameters and will iterate through them 
and count the number of times the parameter is greater than 0. The script will output 
the number greater than 0, or an error message if no parameters are supplied.


Shell Scripting

311
58. An infinite loop is a loop which will never reach its exit condition. We can write 
infinite loops using while, until, or counter for loops (see the example below), but not 
iterator for loops. Why could an iterator for loop never be an infinite loop? For both 
cases below, assume x is initial equal to 0.
Infinite while loop: 
while [ $x –lt 10 ]; do echo $x; done
Infinite for loop: 
for ((i 
=
0;x 
<
10;i
++
); do echo $i; done
59. A palindrome is a string which reads the same forward as backward, as in radar or 
madamimadam (Madam, I’m Adam) but not abacab. Write a script to determine if a 
parameter is a palindrome and output the parameter and whether it is or not.
60. Repeat #59 so that the script receives a list of strings and outputs all of those that are 
palindromes. Output an error message if the script receives no parameters.
61. Write a script which will receive a list of parameters, compute, and output the average 
of the list, or an error if no parameters are supplied.
62. Write a script which will receive a list of parameters and output the number that is 
the largest. If no parameters are supplied, output an error message.
63. Assume array users stores a list of usernames. Write a loop to iterate through the 
usernames and count the numbers who are currently logged in. You can determine if 
a user, x, is logged in by using 
who | grep $x
and seeing if the response is null or 
a value.
64. Assuming array is a variable storing an array of values, what is the difference (if 
any) between 
${array[@]}
and 
${array[*]}
? Between 
"${array[@]}"
and 
"${array[*]}"
?
65. Write a loop to output each letter in the string str using the notation 
$str:i:j
.
66. Write a function which receives a list of values as parameters and computes and out-
puts their sum.
67. Write a function which receives a list of values as parameters and computes and 
returns their sum.
68. Write a function which receives a list of values as parameters and computes and 
returns their average.
69. Revise your function from #68 to return an error code of 9999 if the function receives 
no parameters and so cannot compute an average, otherwise return the average.
70. Rewrite your palindrome script from #60 so that the palindrome checking code is in a 
function which returns a 1 if the parameter passed to it is a palindrome and a 0 if it is not 
a palindrome. Then, call the function using a for loop to iterate over a list of strings and 
based on the return value, output the total number of strings that were palindromes.
71. Redo #70 so that the strings are all stored in an array.



313
C h a p t e r
8
Installing Linux
T
his chapter’s learning objectives are
• To understand the issues involved in operating system installation
• To understand the components that make up the Linux-operating system
• To understand the role of the kernel and the types of kernel design
• To know how to install Linux (both CentOS and Ubuntu)
• To understand what partitions are and how to establish them during installation
• To understand the concept of virtual memory and the need for a swap partition
• To understand the role of SELinux
8.1 INTRODUCTION
Most computers come with an operating system already installed. This is true of all 
Macintosh computers and most computers under the general umbrella of IBM PC com-
patibles (or “windows machines”). You might install a Linux-operating system if
1. You purchase hardware that does not have an operating system already installed
2. You want to dual boot your computer between Linux and another OS (most likely 
Windows)
3. You want to replace your existing operating system (e.g., Windows) or
4. You want to add Linux to a Windows system by installing Linux inside a virtual 
machine
If your choice is #2 or #3 above, you must be careful. Dual booting is a straightfor-
ward operation once both operating systems are installed. However, installing the second 


314

Linux with Operating System Concepts
operating system must not conflict with the initial operating system. One of the steps dur-
ing a Linux installation is partitioning the file system. You must make sure, if another 
operating system is present, that you do not wipe out any portion of that operating system 
when installing the new system. Deleting the native operating system means destroying all 
data currently present. If you have saved that data to an external storage device, then you 
should be able to restore the data to another computer.
8.1.1 Installation Using Virtual Machines
The safest way to install an operating system is into a virtual machine (refer back to 
Chapter 1 to read about virtual machines). A virtual machine is not a computer but instead 
software that mimics another computer. This would require a virtual machine software 
package (e.g., Virtual Box by Sun or VMware Client by VMware). Once the VM program 
is installed and running, you can create a new VM.
Creating a VM requires obtaining the target-operating system’s installation program 
(usually on optical disk) and installing the OS inside the VM. This VM is stored on the disk 
until you are ready to run it. Now, when your computer is running in the native operating 
system, you start the VM program and then run the VM itself. Your computer, through 
the running VM, mimics a different computer as if you had a portal into another com-
puter running its own hardware, operating system, and application software. See Figure 
8.1. Although a VM will require heavy resources (processor, memory, and disk space), 
the installation will not compromise the native operating system such that you are free to 
experiment without risk. Additionally, you can install multiple VMs of different operating 
systems.
8.1.2 Preinstallation Questions
When installing an operating system, you should answer these questions:
1. Why are you installing the operating system?
2. Where are you installing the operating system?
3. How are you installing the operating system?
VM software
running in
memory
(running VM 1)
VM 1
VM 2
VM 3
3 VMs of different
operating systems
stored on disk
Computer
FIGURE 8.1 
Computer running VM.


Installing Linux

315
The “why” is generally answered because you want to explore the new operating system. 
This may be a business decision to see if productivity increases with the new OS. This may 
be a personal choice because you are tired of problems of the current OS (e.g., security 
holes) or because specific software only runs in another OS and you want to use that soft-
ware. It may simply be a hobbyist decision.
The “where” goes back to the earlier list of choices—are you installing the OS on new 
hardware, dual booting, wiping out the old OS, or installing in a VM? This dictates whether 
you have to worry about overwriting the current OS on the disk. Only if you are installing 
for a dual-booting computer do you have to worry about the current contents of the hard 
disk. You might establish the second operating system on a second disk. Alternatively, you 
will have to partition the current hard disk into two or more pieces, one with the native OS 
and one with Linux.
The “how” also goes back to the earlier list of choices although there are more options 
now. First, are you installing the OS anew or are you updating/upgrading the OS? Second, 
are you installing the OS on new hardware (i.e., hardware with no native OS) or are you 
wiping out the current OS, or are you establishing a dual boot? Alternatively, are you 
installing the OS in a VM? Third, are you installing from an optical disk, flash drive, or 
over the network? Finally, are you installing the OS or are you just using a 

Download 5,65 Mb.

Do'stlaringiz bilan baham:
1   ...   114   115   116   117   118   119   120   121   ...   254




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish