Upload
md-ahmed
View
232
Download
0
Embed Size (px)
Citation preview
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 156
1
INDEX
SNo Contents Page No
1 Lab Objective2
2 Introduction About Lab3
3 Guidelines to Students5
List o Sllabus Progras $Namp(
)
5 escri+tion about NI coands1-
iscri+tion about sells2-
Solutions or Progras22
) 0iva uestions and Ansers35
4eerences55
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 256
2
LAB OBJECTIVE
Upon successful completion of this Lab the student will be able to
1 Demonstrate how to use the following Bourne Shell commands cat grep ls more ps chmod finger ftp etc
2 Use the following Bourne Shell constructs test if then if then else if then elif forwhile until and case
3 Learn tracing mechanisms for debugging user ariables BourneShell ariablesreadonl$ ariables positional parameters reading input to a BourneShell scriptcommand substitution comments and eporting ariables ampn addition test onnumeric alues test on file t$pe and test on character strings are coered
(op$ moe and delete files and directories
) rite moderatel$ comple Shell scripts
+ a-e a Shell script eecutable
(reate a profile script to customi0e the user enironment
Use adanced features of ile ransfer 4rotocol 4
5 (ompile source code into ob6ect and eecutable modules
17 8ecute programs written in c under U9amp enironment
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 356
3
INTRODUCTION ABOUT LAB
here are ++ s$stems (ompa 4resario installed in this Labheir configurations are as follows
4rocessor ltD ltthelon = 1+ gt0
lt 2)+ B
ard Dis- 7 gtB
ouse Aptical ouse
9etwor- ampnterface card 4resent
Software
ltll s$stems are configured in DUltL BAA mode ie Students can boot fromindows 4 or Linu as per their lab reuirement
his is er$ useful for students because the$ are familiar with differentAperating S$stems so that the$ can eecute their programs in different programming enironments
8ach student has a separate login for database access
Aracle 5i client ersion is installed in all s$stems An the serer account for eachstudent has been created
his is er$ useful because students can sae their wor- scenarios plCsl programs data related pro6ects etc in their own accounts 8ach studentwor- is safe and secure from other students
Latest echnologies li-e DA 98 and 288 are installed in somes$stems Before submitting their final pro6ect the$ can start doing mini pro6ect from 2nd $ear onwards
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 456
ltS acro ltssembler is installed in all the s$stems
Students can eecute their assembl$ language programs using ltS
ltS is er$ useful students because when the$ eecute their programsthe$ can see contents of 4rocessor egisters and how each instruction is being eecuted in the (4U
ational ose Software is installed in some s$stems
Using this software students can depict UL diagrams of their pro6ects
Softwares installed ( (EE DF1) ltS Aamp(84 288 andDA 98 ational ose
S$stems are proided for students in the 11 ratio
S$stems are assigned numbers and same s$stem is allotted for students when the$do the lab
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 556
)
Guidelines to Students
o to 4un Sell Scri+ts
here are two wa$s $ou can eecute $our shell scripts Ance $ou hae created a scriptfile
ethod 14ass the file as an argument to the shell that $ou want to interpret $our script
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 o run the script pass the filename as an argument to the sh shell
G sh show
ere is the date and timeSat 6un 73 1371) 4S 277+
ethod 2a-e $our script eecutable using the chmod command
hen we create a file b$ default it is created with read and write permission turned onand eecute permission turned off lt file can be made eecutable using chmod
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 a-e the file eecutable
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 256
2
LAB OBJECTIVE
Upon successful completion of this Lab the student will be able to
1 Demonstrate how to use the following Bourne Shell commands cat grep ls more ps chmod finger ftp etc
2 Use the following Bourne Shell constructs test if then if then else if then elif forwhile until and case
3 Learn tracing mechanisms for debugging user ariables BourneShell ariablesreadonl$ ariables positional parameters reading input to a BourneShell scriptcommand substitution comments and eporting ariables ampn addition test onnumeric alues test on file t$pe and test on character strings are coered
(op$ moe and delete files and directories
) rite moderatel$ comple Shell scripts
+ a-e a Shell script eecutable
(reate a profile script to customi0e the user enironment
Use adanced features of ile ransfer 4rotocol 4
5 (ompile source code into ob6ect and eecutable modules
17 8ecute programs written in c under U9amp enironment
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 356
3
INTRODUCTION ABOUT LAB
here are ++ s$stems (ompa 4resario installed in this Labheir configurations are as follows
4rocessor ltD ltthelon = 1+ gt0
lt 2)+ B
ard Dis- 7 gtB
ouse Aptical ouse
9etwor- ampnterface card 4resent
Software
ltll s$stems are configured in DUltL BAA mode ie Students can boot fromindows 4 or Linu as per their lab reuirement
his is er$ useful for students because the$ are familiar with differentAperating S$stems so that the$ can eecute their programs in different programming enironments
8ach student has a separate login for database access
Aracle 5i client ersion is installed in all s$stems An the serer account for eachstudent has been created
his is er$ useful because students can sae their wor- scenarios plCsl programs data related pro6ects etc in their own accounts 8ach studentwor- is safe and secure from other students
Latest echnologies li-e DA 98 and 288 are installed in somes$stems Before submitting their final pro6ect the$ can start doing mini pro6ect from 2nd $ear onwards
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 456
ltS acro ltssembler is installed in all the s$stems
Students can eecute their assembl$ language programs using ltS
ltS is er$ useful students because when the$ eecute their programsthe$ can see contents of 4rocessor egisters and how each instruction is being eecuted in the (4U
ational ose Software is installed in some s$stems
Using this software students can depict UL diagrams of their pro6ects
Softwares installed ( (EE DF1) ltS Aamp(84 288 andDA 98 ational ose
S$stems are proided for students in the 11 ratio
S$stems are assigned numbers and same s$stem is allotted for students when the$do the lab
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 556
)
Guidelines to Students
o to 4un Sell Scri+ts
here are two wa$s $ou can eecute $our shell scripts Ance $ou hae created a scriptfile
ethod 14ass the file as an argument to the shell that $ou want to interpret $our script
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 o run the script pass the filename as an argument to the sh shell
G sh show
ere is the date and timeSat 6un 73 1371) 4S 277+
ethod 2a-e $our script eecutable using the chmod command
hen we create a file b$ default it is created with read and write permission turned onand eecute permission turned off lt file can be made eecutable using chmod
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 a-e the file eecutable
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 356
3
INTRODUCTION ABOUT LAB
here are ++ s$stems (ompa 4resario installed in this Labheir configurations are as follows
4rocessor ltD ltthelon = 1+ gt0
lt 2)+ B
ard Dis- 7 gtB
ouse Aptical ouse
9etwor- ampnterface card 4resent
Software
ltll s$stems are configured in DUltL BAA mode ie Students can boot fromindows 4 or Linu as per their lab reuirement
his is er$ useful for students because the$ are familiar with differentAperating S$stems so that the$ can eecute their programs in different programming enironments
8ach student has a separate login for database access
Aracle 5i client ersion is installed in all s$stems An the serer account for eachstudent has been created
his is er$ useful because students can sae their wor- scenarios plCsl programs data related pro6ects etc in their own accounts 8ach studentwor- is safe and secure from other students
Latest echnologies li-e DA 98 and 288 are installed in somes$stems Before submitting their final pro6ect the$ can start doing mini pro6ect from 2nd $ear onwards
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 456
ltS acro ltssembler is installed in all the s$stems
Students can eecute their assembl$ language programs using ltS
ltS is er$ useful students because when the$ eecute their programsthe$ can see contents of 4rocessor egisters and how each instruction is being eecuted in the (4U
ational ose Software is installed in some s$stems
Using this software students can depict UL diagrams of their pro6ects
Softwares installed ( (EE DF1) ltS Aamp(84 288 andDA 98 ational ose
S$stems are proided for students in the 11 ratio
S$stems are assigned numbers and same s$stem is allotted for students when the$do the lab
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 556
)
Guidelines to Students
o to 4un Sell Scri+ts
here are two wa$s $ou can eecute $our shell scripts Ance $ou hae created a scriptfile
ethod 14ass the file as an argument to the shell that $ou want to interpret $our script
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 o run the script pass the filename as an argument to the sh shell
G sh show
ere is the date and timeSat 6un 73 1371) 4S 277+
ethod 2a-e $our script eecutable using the chmod command
hen we create a file b$ default it is created with read and write permission turned onand eecute permission turned off lt file can be made eecutable using chmod
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 a-e the file eecutable
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 456
ltS acro ltssembler is installed in all the s$stems
Students can eecute their assembl$ language programs using ltS
ltS is er$ useful students because when the$ eecute their programsthe$ can see contents of 4rocessor egisters and how each instruction is being eecuted in the (4U
ational ose Software is installed in some s$stems
Using this software students can depict UL diagrams of their pro6ects
Softwares installed ( (EE DF1) ltS Aamp(84 288 andDA 98 ational ose
S$stems are proided for students in the 11 ratio
S$stems are assigned numbers and same s$stem is allotted for students when the$do the lab
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 556
)
Guidelines to Students
o to 4un Sell Scri+ts
here are two wa$s $ou can eecute $our shell scripts Ance $ou hae created a scriptfile
ethod 14ass the file as an argument to the shell that $ou want to interpret $our script
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 o run the script pass the filename as an argument to the sh shell
G sh show
ere is the date and timeSat 6un 73 1371) 4S 277+
ethod 2a-e $our script eecutable using the chmod command
hen we create a file b$ default it is created with read and write permission turned onand eecute permission turned off lt file can be made eecutable using chmod
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 a-e the file eecutable
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 556
)
Guidelines to Students
o to 4un Sell Scri+ts
here are two wa$s $ou can eecute $our shell scripts Ance $ou hae created a scriptfile
ethod 14ass the file as an argument to the shell that $ou want to interpret $our script
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 o run the script pass the filename as an argument to the sh shell
G sh show
ere is the date and timeSat 6un 73 1371) 4S 277+
ethod 2a-e $our script eecutable using the chmod command
hen we create a file b$ default it is created with read and write permission turned onand eecute permission turned off lt file can be made eecutable using chmod
Step 1 create the script using i e or ed
or eample the script file show has the following lines
echo ere is the date and timedate
Step 2 a-e the file eecutable
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 656
+
G chmod uE scriptHfileG chmod uE show
Step 3 o run the script 6ust t$pe the filename
G showere is the date and timeSat 6un 73 1371) 4S 277+
o to run C +rogras
Step 1 Use an editor such as i e or ed to write the program he name of the file
containing the program should end in c
or eample the file showc contains the following lines
mainI
printfJ welcome to gt98( JK
Step 2 Submit the file to (( the ( (ompiler
G cc showc
ampf the program is o-a$ the compiled ersion is placed in a file called aout
Step 3 o run the program t$pe aout
G aout
elcome to gt98(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 756
List of Lab Exercises
S$llabus 4rograms 9U
67781
Session 1
1 Log in to the s$stem2 Use Mi editor to create a file called m$filett which contain some tet3 (orrect t$ping errors during creation Sae the file) Logout of the file
Session 2
a Log into the s$stem b Apen the file created in session 1c ltdd some tetd (hange some tete delete some tetf Sae the changesg Logout of the s$stem
67782
a log into the s$stem b Use the cat command to create a file containing the following data (all it
mutable use tabs to separate the fields12) rai 1)+)327 ramu 2+2+37 sita 3+1)1)7 ra6u 21+
c use the cat command to displa$ the file m$ tabled use the i command to correct an$ errors in the file m$ tablee use the sort command to sort the file m$ table according to the first field (all the
sorted file m$ tablesame namef print the file m$ tableg use the cut N paste commands to swap fields 2 and 3 m$ table (all it
m$tablesame nameh print the new file m$ tablei logout of the s$stem
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 856
67783
a log in the s$stem b use the appropriate commands to determine ur login shell
c use the CetcCpasswd file to erif$ the result of step bd use the who command redirect the result to a file called m$file1Use the morecommand to see the contents of m$file1
e Use the date and who commands in seuence Oin one line such that the output ofdate will displa$ on the screen and the output of who will be redirected to a filecalled m$ file2Use the more command to chec- the contents of m$file2
a write a sed command that deletes the first character in each line in a file b write a sed command that deletes the character before the last character in each
line in a filec rite a sed command that swaps the files and second words in each line in a file
6778
a pipe ur CetcCpasswd file to aw- and print out the home director$ of each user b Deelop an interactie grep script that as-s for a word and a file name and then
tells how man$ lines contain that wordc epeatd 4art using aw-
67785
a rite lt shell script that ta-es a command Pline argument and reports on whether it is
directr$ a fileor something else b rite a shell script that accepts one or more file name as a arguments and conerts allof thenm to uppercaseproided the$ eits in the current director$c rite a shell script that determines the period for which a specified user is wor-ing onthe s$stem
6778
a write a shell script that accepts a file name starting and ending line numbers asarguments and displa$s all the lines between the gien line numbers
b write a shell script that deletes all lines containing a specified word amp one or more
files supplied as arguments to it
6778)
a rite a shell script that computes the gross salar$ of a emplo$ee according to thefollowing
1 if basic salar$ is Q1)77 then lt 17R of the basic and Dlt 57R of the basic
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 956
5
2 if basic salar$ is T1)77 then lt )77 and Dlt 5R of the basiche basic salar$ is entered interactiel$ through the -e$ board
b rite a shell script that accepts two integers as its arguments and computes thealue of first number raised to the power of the second number
6778
a rite an interactie file handling shell program Let it offer the user the choice ofcop$ing remoing renaming or lin-ing files Ance the use has made a choicehae the program as- the user for necessar$ information such as the file namenew name and so on
b rite a shell script that ta-es a login name as command Pline argument andreports when that person logs in
c rite a shell script which receies two files names as arguments ampt should chec-whether the two file contents are same or not ampf the$ are same then second file
should be deleted
6778 9
a rite a shell script that displa$s a list of all files in the current director$ to whichthe user has read write and eecute permissions
b Deelop an interactie script that as-s for a word and file name and then tells howman$ times that word occurred in the file
c rite a shell script to perform the following string operations
1 o etract a sub string from a gien string2 o find the length of a gien string
88F 17
rite a ( program that ta-es one or more file or director$ names as command line inputand reports the following information on the file
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
88F 11
rite ( program that simulate the following uni commandsa m b cp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1056
17
88F 12
rite a c program that simulates ls commandUse s$stem calls Cdirector$ lt4amp
Basic Unix commands
(ommand (lt
S$nta cat argumentV specific fileV
Description Jcat is short for concatenate his command is used tocreate iew and concatenate files
8amples cat CetcCpasswd
his command displa$s the CetcCpasswd file on $our screen
cat CetcCprofile
his command displa$s the CetcCprofile file on $our screen 9otice that some of the contents of this file ma$ scroll off of$our screen
cat file1 file2 file3 T file
his command combines the contents of the first three filesinto the fourth file
(ommand pwd
S$nta pwd
Description pwd stands for print wor-ing director$ ampt displa$s$our current position in the U9amp files$stem
8amples pwd
here are no options or arguments with the pwdcommand ampt is simpl$ used to report $our current wor-ing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1156
11
director$
(ommand ls
S$nta ls optionsV namesV
Description ls stands for list ampt is used to list information aboutfiles and directories
8amples ls
his is the basic ls command with no options ampt proides aer$ basic listing of the files in $our current wor-ingdirector$ ilenames beginning with a decimal are consideredhidden files and the$ are not shown
ls a
he a option tells the ls command to report information aboutall files including hidden files
ls l
he l option tells the ls command to proide a long listingof information about the files and directories it reports helong listing will proide important information about file
permissions user and group ownership file si0e and creationdate
ls al
his command proides a long listing of information about allfiles in the current director$ ampt combines the functionalit$ ofthe a and l options This is probably the most used version of
the ls command
ls al Cusr
his command lists long information about all files in theCusr director$
ls al Cusr W more
his command lists long information about all files in theCusr director$ and all subdirectories of Cusr he option
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1256
12
tells the ls command to proide a recursive listing of all filesand subdirectories
ls ld Cusr
ather than list the files contained in the Cusr director$ thiscommand lists information about the Cusr director$ itselfwithout generating a listing of the contents of Cusr his iser$ useful when $ou want to chec- the permissions of thedirector$ and not the files the director$ contains
(ommand m
S$nta m optionsV sources target
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the file
Description he m command is used to moe and rename files
8amples m (hapter1 (hapter1bad
his command renames the file (hapter1 to the new name(hapter1bad
m (hapter1 garbage
his command renames the file (hapter1 to the new namegarbage 9otice that if garbage is a director$ (hapter1would be moed into that director$
m (hapter1 Ctmp
his command moes the file (hapter1 into the director$named Ctmp
m tmp tmpold
ltssuming in this case that tmp is a director$ this eamplerenames the director$ tmp to the new name tmpold
(ommand rm
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1356
13
S$nta rm optionsV files
Aptions d director$unlin- ampL8 een if it is a nonempt$ director$
superuser onl$
f force ignore noneistent files neer prompt
i interactie prompt before an$ remoal
r recursie remoe the contents of directories recursiel$
erbose eplain what is being done
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoingfiles and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1bad
assuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou must
answer $ for $es for each file $ou reall$ want to delete hiscan be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1456
1
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cp
S$nta cp optionsV file1 file2
cp optionsV files director$
Aptions b bac-up files that are about to be oerwritten or remoedi interactie modeK if dest eists $ouXll be as-ed whether to
oerwrite the filep preseres the original fileXs ownership group
permissions and timestamp
Description he cp command is used to cop$ files and directories
9ote that when using the cp command $ou must alwa$sspecif$ both the source and destination of the files to becopied
8amples cp profile profileba-
his command copies $our profile to a file named
profileba-
cp CusrCfredC(hapter1
his command copies the file named (hapter1 in theCusrCfred director$ to the current director$ his eampleassumes that $ou hae write permission in the current
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1556
1)
director$
cp CusrCfredC(hapter1 CusrCmar$
his command copies the (hapter1 file in CusrCfred to thedirector$ named CusrCmar$ his eample assumes that $ouhae write permission in the CusrCmar$ director$
(ommand grep
S$nta grep optionsV regular epression filesV
Aptions i caseinsensitie searchn show the line along with the matched line inert match eg find all lines that do 9A
matchw match entire words rather than substrings
Description hin- of the grep command as a search commandmost people wish it was named search ampt is used tosearch for tet strings within one or more files
8amples grep XfredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file ampt will find and print onthe screen all of the lines in this file that contain the tetstring XfredX including lines that contain usernames li-e fred and also alfred
grep X]fredX CetcCpasswd
his command searches for all occurrences of the tet stringXfredX within the CetcCpasswd file but also reuires that the
f in the name fred be in the first column of each recordthatXs what the caret character tells grep Using this moreadanced search a user named alfred would not bematched because the letter a will be in the first column
grep X6oeX [
his command searches for all occurrences of the tet string
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1656
1+
X6oeX within all files of the current director$
(ommand m-dir
S$nta m-dir optionsV director$ name
Description he m-dir command is used to create new directoriessubdirectories
8amples m-dir tmp
his command creates a new director$ named tmp in $ourcurrent director$ his eample assumes that $ou hae the
proper permissions to create a new subdirector$ in $ourcurrent wor-ing director$
m-dir memos letters email
his command creates three new subdirectories memosletters and email in the current director$
m-dir CusrCfredCtmp
his command creates a new director$ named tmp in the
director$ CusrCfred tmp is now a subdirector$ ofCusrCfred his eample assumes that $ou hae the proper permissions to create a new director$ in CusrCfred
m-dir p ChomeC6oeCcustomerCacme
his command creates a new director$ namedChomeC6oeCcustomerCacme and creates an$ intermediatedirectories that are needed ampf onl$ ChomeC6oe eisted to beginwith then the director$ customer is created and thedirector$ acme is created inside of customer
(ommand rmdir
S$nta rmdir optionsV directories
Description he rm command is used to remoe files anddirectories arning be er$ careful when remoing
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1756
1
files and directoriesY
8amples rm (hapter1bad
his command deletes the file named (hapter1badassuming $ou hae permission to delete this file
rm (hapter1 (hapter2 (hapter3
his command deletes the files named (hapter1(hapter2 and (hapter3
rm i (hapter1 (hapter2 (hapter3
his command prompts $ou before deleting an$ of the threefiles specified he i option stands for inquire Zou mustanswer $ for $es for each file $ou reall$ want to delete his
can be a safer wa$ to delete files
rm [html
his command deletes all files in the current director$ whosefilename ends with the characters html
rm inde[
his command deletes all files in the current director$ whosefilename begins with the characters inde
rm r newnoel
his command deletes the director$ named newnoel hisdirector$ and all of itsX contents are erased from the dis-including an$ subdirectories and files
(ommand cd chdir
S$nta cd name of director$ $ou want to moe toV
Description cd stands for change director$ ampt is the primar$command for moing around the files$stem
8amples cd Cusr
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1856
1
his command moes $ou to the Cusr director$ Cusr becomes $our current wor-ing director$
cd CusrCfred
oes $ou to the CusrCfred director$
cd Cu[Cf[
oes $ou to the CusrCfred director$ if this is the onl$director$ matching this wildcard pattern
cd
ampssuing the cd command without an$ arguments moes $ou
to $our home director$
cd
Using the Forn shell this command moes $ou bac- to $our preious wor-ing director$ his is er$ useful when $ouXre inthe middle of a pro6ect and -eep moing bac-andforth between two directories
(ommand -ill
S$nta -ill optionsV ampDs
Description -ill ends one or more process ampDs ampn order to do this $oumust own the process or be designated a priileged user ofind the process ampD of a certain 6ob use ps
8amples
(ommand ps
S$nta ps optionsV
Description he ps command process statistics lets $ou chec-the status of processes that are running on $our Uni
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 1956
15
s$stem
8amples ps
he ps command b$ itself shows minimal information aboutthe processes you are running ithout an$ arguments this
command will not show information about other processesrunning on the s$stem
ps f
he f argument tells ps to suppl$ full information about the processes it displa$s ampn this eample ps displa$s fullinformation about the processes you are running
ps e
he e argument tells the ps command to show every processrunning on the s$stem
ps ef
he e and f arguments are normall$ combined li-e this toshow full information about eer$ process running on thes$stem This is probably the most often-used form of the ps
command
ps ef W more
Because the output normall$ scrolls off the screen the outputof the ps ef command is often piped into the more commandhe more command lets $ou iew one screenful ofinformation at a time
ps fu fred
his command shows full information about the processescurrentl$ being run b$ the user named fred the u option lets$ou specif$ a username
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2056
27
6 se Sells
ell most li-el$ because the are a simple wa$ to string together a bunch of U9ampcommands for eecution at an$ time without the need for prior compilation ltlso because
its generall$ fast to get a script going 9ot forgetting the ease with which other scripterscan read the code and understand what is happening Lastl$ the$ are generall$completel$ portable across the whole U9amp world as long as the$ hae been written to acommon standard
ampe Sell istor
he basic shells come in three main language forms hese are in order of creation slt
cs and =s Be aware that there are seeral dialects of these script languages which tendto ma-e them all slightl$ platform specific here these differences are -nown to causedifficulties amp hae made special notes within the tet to highlight this fact he different
dialects are due in the main to the different U9amp flaours in use on some platforms ltllscript languages though hae at their heart a common core which if used correctl$ willguarantee portabilit$
gtourne Sell
istoricall$ the s language was the first to be created and goes under the name of heBourne Shell ampt has a er$ compact s$nta which ma-es it obtuse for noice users buter$ efficient when used b$ eperts ampt also contains some powerful constructs built inAn U9amp s$stems most of the scripts used to start and configure the operating s$stemare written in the Bourne shell ampt has been around for so long that is it irtuall$ bug free
amp hae adopted the Bourne shell s$nta as the defacto standard within this boo-
C Sell
9et up was he ( Shell cs so called because of the similar s$ntactical structures tothe ( language he U9amp man pages contain almost twice as much information for the( Shell as the pages for the Bourne shell leading most users to beliee that it is twice asgood his is a shame because there are seeral compromises within the ( Shell which
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2156
21
ma-es using the language for serious wor- difficult chec- the list of bugs at the end ofthe man pagesY rue there are so man$ functions aailable within the ( Shell that if oneshould fail another could be found he point is do $ou really want to spend $our timefinding all the alternatie wa$s of doing the same thing 6ust to -eep $ourself out oftrouble he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the
default login shell for most users he features that guarantee its continued use in thisarena are aliases and histor$ lists here are rumours howeer that ( Shell is destined to be phased out with future U9amp releases onl$ supporting s and =s Differences between cs and s s$nta will be highlighted where appropriate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2256
22
8orne Sell
Lastl$ we come to he Forne Shell =s made famous b$ ampBXs ltamp flaour of U9amphe Forne shell can be thought of as a superset of the Bourne shell as it contains the
whole of the Bourne shell world within its own s$nta rules he etensions oer andaboe the Bourne shell eceed een the leel of functionalit$ aailable within the ( Shellbut without an$ of the compromisesY ma-ing it the obious language of choice for realscripters oweer because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing his ma$ change howeer b$the time this boo- is published Forne Shell does contain aliases and histor$ lists aplent$ but ( Shell users are often put off b$ its dissimilar s$nta 4erseere it will pa$ offeentuall$ ltn$ s s$nta element will wor- in the =s without change
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2356
23
SOLampIONS
67781
Session 1
1 Log in to te sste2 se 0i editor to create a ile called ilett ic contain soe
tet
3 Correct t+ing errors during creation
Save te ile
5 Logout o te ile
Sol
G login Quser nameT G password [[[[[[
G i^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments
$pe Q8scT w m$file
GSession 2
1 Log into te sste
2 O+en te ile created in session 1
3 Add soe tet
Cange soe tet
5 delete soe tet
Save te canges
) Logout o te sste
SolG login Quser nameTG password [[[[[[
G i m$file
^ Uni is (ase Sensitie^ 9eer leae the (omputer without logging out when $ou are wor-ing in atime sharing or networ- enironments^ Shell 4rogramming
w
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2456
2
67782
Log into te sste
se te cat coand to create a ile containing te olloing data Call it
utable use tabs to se+arate te ields
125 ravi 15532- rau 22)
3- sita 315
15- raju 21
a use te cat coand to dis+la te ilelt table
b use te vi coand to correct an errors in te ilelt table
c use te sort coand to sort te ile table according to te irst
ield Call te sorted ile table$sae nae(
d +rint te ile table
e use te cut +aste coands to sa+ ields 2 and 3 table Call
it table$sae nae( +rint te ne ilelt table
g logout o te sste
Sol
G login Quser nameT G password[[[[[[
G cat Pc11
12) QtabT rai QtabT 1)+) QtabT327 QtabT ramu QtabT 2+2 QtabT+37 QtabT sita QtabT 3+1) QtabT1)7 QtabT ra6u QtabT 21+ QtabT
G cat m$fileGwhoWmoreG sort E7 1 m$table
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2556
2)
67783
a log in te sste
b use te a++ro+riate coands to deterine ur login sellc use te etc+assd ile to veri te result o ste+ b
d use te o coand redirect te result to a ile called ile1se
te ore coand to see te contents o ile1
e se te date and o coands in seBuence $in one line( suc tat
te out+ut o date ill dis+la on te screen and te out+ut o o
ill be redirected to a ile called ile2se te ore coand to
cec= te contents o ile2
rite a sed coand tat deletes te irst caracter in eac line in a
ile
g rite a sed coand tat deletes te caracter beore te last
caracter in eac line in a ile 6rite a sed coand tat sa+s te iles and second ords in eac
line in a ile
Sol
G login Quser nameTG password[[[[[[
G echo GS8LLcsh
G who TW m$file1 G more m$file1
G dateWwho Tm$file2G more m$file2
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2656
2+
6778
+i+e ur etc+assd ile to a= and +rint out te oe director o eac user
evelo+ an interactive gre+ scri+t tat as=s or a ord and a ile nae and ten
tells o an lines contain tat ord
4e+eatPart using a=
$d( Sol
G aw- _G2 `(omputers` NN G3 T17777 IprintSalesdat
IP
1 (lothing 3111 (omputers 51+11 etboo-s 21312
2 (lothing 32)22 (omputers 12322 Supplies 2222 et boo-s 1)+2
OP
2 (omputers 1232
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2756
2
67785
a( 6rite A sell scri+t tat ta=es a coand line arguent and re+orts on eter
it is directr lta ileltor soeting else
b( 6rite a sell scri+t tat acce+ts one or ore ile nae as a arguents andconverts all o ten to u++ercaselt+rovided te eits in te current director
c( 6rite a sell scri+t tat deterines te +eriod or ic a s+eciied user is
or=ing on te sste
$a( Sol
echo 8nter a file nameread f if f Gf Vthen
echo ileelif d Gf Vthen
echo Director$elseecho 9otfi
Out+ut
Director$
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2856
2
6778
$a( 6rite a sell scri+t tat acce+ts a ile nae starting and ending line nubers
as arguents and dis+las all te lines beteen te given line nubers
$b( 6rite a sell scri+t tat deletes all lines containing a s+eciied ord I one or
ore iles su++lied as arguents to it
$a( Sol
G aw- _9Q2 WW 9T Iprint G7 ) linesdat
ampC4 line1
line2line3lineline)
AC4 line1line)
$b( Sol
i1while Gi le G Vdo
grep Uni Gi T Gi
done
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 2956
25
6778)
a( 6rite a sell scri+t tat co+utes te gross salar o a e+loee according to te
olloing
1( i basic salar is D15-- ten 4A 1-E o te basic and A F9-E o te basic2( i basic salar is 15-- ten 4A 5-- and A F9E o te basic
ampe basic salar is entered interactivel troug te =e board
$b(6rite a sell scri+t tat acce+ts to integers as its arguents and co+utes
te value o irst nuber raised to te +oer o te second nuber
echo 8nter the Salar$ read salif GsalQ1)77V thendaepr Gsal[57C177
hraepr Gsal[17C177gsalepr Gsal EGhraEGdaecho JGgsal`elif GsalT1)77Vhra)77daepr Gsal[5C177gsalepr GsalEGhraEGdagrossepr Gsa E Gda E Ghrafifi
baG1 bG2cpowGaGbecho`Gc`
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3056
37
6778
$a( 6rite an interactive ile andling sell +rogra Let it oer te user te
coice o co+ing ltreoving ltrenaing or lin=ing iles Once te use as ade a
coicelt ave te +rogra as= te user or necessar inorationlt suc as te ilenae ltne nae and so on
$b( 6rite a sell scri+t tat ta=es a login nae as coand line arguent and
re+orts en tat +erson logs in
$c( 6rite a sell scri+t ic receives to iles naes as arguents It sould
cec= eter te to ile contents are sae or not I te are sae ten second
ile sould be deleted
P4OG4AH
echo 8nter amp ile 9ameread f1echo 8nter ampamp ile 9ameread f2dcmp Gf1 Gf2d1if Gd e Gd2 Vthen
echo wo iles are similar and Gf2 is deletedrm Gf2
elseecho wo iles differ each other
fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3156
31
6778 9
$a( 6rite a sell scri+t tat dis+las a list o all iles in te current director to
ic te user as read rite and eecute +erissions
$b( evelo+ an interactive scri+t tat as=s or a ord and ile nae and ten
tells o an ties tat ord occurred in te ile
$c( 6rite a sell scri+t to +eror te olloing string o+erations1( ampo etract a sub string ro a given string
2( ampo ind te lengt o a given string
$a( P4OG4AH
ile 9ame listsh
YCbinCbashread p 8nter a director$ name dnif d Gdn VK then printf niles in the director$ Gdn are n for fn in ls Gdn do if d GdnCGfn VK then printf QGfnT Director$ elif f GdnCGfn V then printf Gfn ile fi if r GdnCGfn VK then printf ead fi if w GdnCGfn VKthen
printf rite fi if GdnCGfn VKthen
printf 8ecute fi printf n doneelse
printf nGdn not eists or not a director$fi
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3256
32
$b( P4OG4AH
ile 9ame wcountshYCbinCbash
read p 8nter a file name fnif test f Gfnthen echo he contents of the file Gfn is cat Gfn echo 9o of Line wc l Gfn echo 9o of ords wc w Gfn echo 9o of (haracters wc c Gfnelse echo Gfn is not eists or not a filefi
$c( P4OG4AH
4rint J8nter the Stringc`read strampnstrlenGI strampn print the string length is GstrlenG strlenscr
AC48nter the String 9ow is the timehe String length 1)
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3356
33
88F 17
6rite a C +rogra tat ta=es one or ore ile or director naes as coand line
in+ut and re+orts te olloing inoration on te ile
1 file t$pe2 number of lin-s3 read write and eecute permissions time of last access
9ote use Cfstat s$stem calls
P4OG4AH
includeQstdiohTmain
IampL8 [streamKint bufferHcharacterKstreamfopenJtest``r`KifstreamampL8[7Ifprintfstderr`8rror opening fileprinted to standard errorn`KfclosestreamKeit1K
iffclosestream8AIfprintfstderr`8rror closing streamprinted to standard errornKeit1KreturnK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3456
3
88F 11
6rite C +rogra tat siulate te olloing uni coands
$a( v
$b( c+
C[ ile 9ame bspace1c [CincludeQfcntlhTincludeQunistdhTincludeQstdiohTmainint argcchar [argVIampL8 [fpKchar chKint sc7K
fpfopenarg1VrKiffp9ULL printfunable to open a filearg1VKelseI whileYfeoffp I chfgetcfpK ifchX X scEEK
printfno of spaces RdscK printfnK fclosefpK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3556
3)
88F 12
6rite a c +rogra tat siulates ls coand
$se sste calls director API(
P4OG4AH
includeQstdiohTincludeQfcntlhTincludeQstdlibhTmainint argcchar [argVI
int fdiKchar ch1VK
if argcQ2I printfUsage m$cat filenamenK eit7K
fdopenarg1VAHDA9LZKiffd1 printfRs is not eistarg1VK
elseI printf(ontents of the file Rs is narg1VK whilereadfdch1T7 printfRcch7VK closefdK
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3656
3+
0iva uestions Ansers
What is a Make file
a-e file is a utilit$ in Unix to help compile large programs ampt helps b$ onl$ compilingthe portion of the program that has been changed
Could you tell something about the Unix System Kernel
The kernel is the heart o the UNIX operating system itsresonsi$le or controllin the comampters resoamprces andschedamplin ampser o$s so that each one ets its air share oresoamprces(
How can you tell what shell you are running on UNsystem
)oamp can do the Echo RANDO+( It ill retamprn a ampndeined-aria$le i oamp are rom the C0hell ampst a retamprn romt i oampare rom the Boamprne shell and a 1 diit random nampm$ers i oampare rom the 2orn shell( )oamp coampld also do a s l and look orthe shell ith 345
What do you mean by uarea user area$ or ublockThis contains the ri-ate data that is maniamplated onl $ the2ernel( This is local to the 6rocess i(e( each rocess isallocated a amparea(
What scheme does the Kernel in Unix System follow whilechoosing a swaamp deice among the multiample swaamp deices
2ernel ollos Roampnd Ro$in scheme choosin a sa de-iceamon the mampltile sa de-ices in Unix System V(
(ist the system calls used for amprocess management)
0stem calls Descritionork78 To create a ne rocessexec78 To execampte a ne roram in a rocessait78 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3756
3
How do you change ile +ccess ermissions
E-er ile has olloin attri$amptes9oners user ID 7 $it inteer 8oners roamp ID 7 $it inteer 8
ltile access mode ord=r x r x r x7ampser ermissionroamp ermissionothers ermission8rread rite xexecampteTo chane the access mode e ampse chmod7ilenamemode8(Examle9To chane mode o mile to =rrrgt 7ie( read riteermission or ampser 345
-xamplain the layered asampect of a UN system What are thelayers What does it mean to say they are layers
A UNIX system has essentiall three main laers9( The hardare( The operating system kernel( The ampserle-el roramsThe kernel hides the sstems hardare ampnderneath ana$stract hihle-el rorammin interace( It is resonsi$le orimlementin man o the acilities that ampsers and ampserle-elrorams take or ranted(The kernel assem$les all o the olloin UNIX concets romloerle-el 345
What is the use of greamp0 command
=re is a attern search command( It searches or the atternseciied in the command line ith aroriate otion in aile7s8(0ntax 9 re Examle 9 re mx mcaile
What difference between cmamp and diff commands
cm Comares to iles $te $ $te and dislas the irst
mismatchdi tells the chanes to $e made to make the iles identical
What is the significance of the 1tee2 command
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3856
3
It reads the standard inampt and sends it to the standard oamptampthile redirectin a co o hat it has read to the ile seciied$ the ampser(
s du0 a command f so3 what is its use
)es it stands or =disk ampsae( ith the hel o this commandoamp can ind the disk caacit and free space o the disk(
How to terminate a amprocess which is running and thesampecialty on command kill 4
ith the hel o kill command e can terminate the rocess(0ntax9 kill id 2ill kills all rocesses in oampr sstem excetthe loin shell(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 3956
35
-xamplain kill$ and its ampossible return alues
There are oampr ossi$le resamplts rom this call9=kill78 retamprns ( This imlies that a rocess exists ith the i-en
6ID and the sstem oampld allo oamp to send sinals to it( It issstemdeendent hether the rocess coampld $e a om$ie(=kill78 retamprns =errno E0RC either no rocess exists iththe i-en 6ID or 345
What does the command 1 5who 6 sort 7logfile 8 newfile2do
The inampt rom a ie can $e com$ined ith the inampt rom a ile( The trick is to ampse the secial sm$ol 7a hhen8 or thosecommands that reconie the hhen as std inampt(
In the a$o-e command the oamptampt rom ho $ecomes the stdinampt to sort meanhile sort oens the ile 345
What are shell ariables
0hell -aria$les are secial -aria$les a name-alampe air createdand maintained $ the shell(Examle9 6AT O+E +AIL and TER+
How many ampromampts are aailable in a UN system
To romts 60 76rimar 6romt8 60F 70econdar 6romt8(
s it ampossible to create new a file system in UN
Use =samp command( The sstem asks or assord and hen-alid entr is made the ampser ains samper ampser 7admin8 ri-ilees(
How the Kernel handles the coampy on write bit of a ampage3when the bit is set
In sitampations like here the co on rite $it o a ae is setand that ae is shared $ more than one rocess the 2ernelallocates ne ae and coies the content to the ne ae andthe other rocesses retain their reerences to the old ae( Atercoin the 2ernel ampdates the ae 345
ierence beteen te or=$( and vor=$( sste call
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4056
7
During the for- s$stem call the Fernel ma-es a cop$ of the parent processs addressspace and attaches it to the child processBut the for- s$stem call do not ma-es an$cop$ of the parents address space so it is faster than the for- s$stem call he child process as a result of the for- V
How the Kernel handles the fork$ system call in traditionalUnix and in the System Unix3 while swaampamping
2ernel in traditional Unix makes the damplicate co o thearents address sace and attaches it to the childs rocesshile sain( 2ernel in 0stem V Unix maniamplates thereion ta$les ae ta$le and data ta$le entries $incrementin the reerence coampnt o the reion ta$le o sharedreions(
What are the re9uirements for a swaampamper to work
The saer orks on the hihest schedamplin riorit( ltirstl itill look or an sleein rocess i not oampnd then it ill look orthe readtorampn rocess or sain( Bampt the maorreGampirement or the saer to ork the readtorampn rocessmampst $e coreresident or at least F seconds $eore sainoampt( And or sain 345
What is -xampansion swaamp
At the time hen an rocess reGampires more memor than it is
camprrentl allocated the 2ernel erorms Exansion sa( To dothis 2ernel reser-es enoamph sace in the sa de-ice( Then theaddress translation main is adampsted or the ne -irtampaladdress sace $ampt the hsical memor is not allocated( At last2ernel sas the 345
What is ork swaamp
ork78 is a sstem call to create a child rocess( hen the arentrocess calls ork78 sstem call the child rocess is created andi there is short o memor then the child rocess is sent to the
readtorampn state in the sa de-ice and retamprn to the ampser stateithoampt sain the arent rocess( 345
What are the entities that are swaampamped out of the mainmemory while swaampamping the amprocess out of the mainmemory
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4156
1
All memor sace occampied $ the rocess rocesss ampareaand 2ernel stack are saed oampt theoreticall(6racticall i the rocesss amparea contains the AddressTranslation Ta$les or the rocess then 2ernel imlementationsdo not sa the amparea(
s the rocess before and after the swaamp are the same ie reason
6rocess $eore sain is residin in the rimar memor inits oriinal orm( The reions 7text data and stack8 ma not $eoccampied ampll $ the rocess there ma $e e emt slots inan o the reions and hile sain 2ernel do not $othera$oampt the emt slots hile sain the rocess oamptAtersain 345
What are the eents done by the Kernel after a amprocess isbeing swaampamped out from the main memory
hen 2ernel sas the rocess oampt o the rimar memor iterorms the olloin92ernel decrements the Reerence Coampnt o each reion o therocess( I the reerence coampnt $ecomes ero sas the reionoampt o the main memor(2ernel allocates the sace or the sain rocess in the sade-ice(2ernel locks the other sain rocess hile 345
What is maor difference between the Historic Unix and thenew ltS= release of Unix System in terms of MemoryManagement
istoric Unix ampses 0ain gt entire rocess is transerred tothe main memor rom the sa de-ice hereas the Unix0stem V ampses Demand 6ain gt onl the art o the rocess ismo-ed to the main memor( istoric Unix ampses one 0aDe-ice and Unix 0stem V allo mampltile 0a De-ices
What is an adantage of executing a amprocess inbackground
The most common reason to ampt a rocess in the $ackroampnd isto allo oamp to do somethin else interacti-el ithoampt aitinor the rocess to comlete( At the end o the command oamp addthe secial $ackroampnd sm$ol H( This sm$ol tells oampr shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4256
2
to execampte the i-en command in the $ackroampnd(Examle9 c ( 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX sstem the sstemcreates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9
Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4356
3
What is a gtombie
hen a roram orks and the child inishes $eore the arentthe kernel still kees some o its inormation a$oampt the child in
case the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an en-ironment -aria$le is done $ ampsinKeten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creationo a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4456
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences C6U allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and
resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4556
)
What is a shell
A shell is an interacti-e ampser interace to an oeratin sstemser-ices that allos an ampser to enter commands as character
strins or throamph a rahical ampser interace(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and otherinormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The th
address oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a ile sstemto a director o another ile sstem the ampnmoampnt sstem calldetaches a ile sstem( hen oamp moampnt another ile sstem onto oampr director oamp are essentiall slicin one director treeonto a $ranch in another director tree( The irst arampment to345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the ile te to indicate that the ile is a ie director orsecial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(
ltor examle9 I the de-ice is a disk maor 345
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames ondierent comampters(
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4656
+
0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 oen ilecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ilelseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
What Haampampens when you execute a amprogram
hen oamp execampte a roram on oampr UNIX system thesstem creates a secial en-ironment or that roram( Thisen-ironment contains e-erthin needed or the sstem to rampnthe roram as i no other roram ere rampnnin on the sstem(Each rocess has rocess context hich is e-erthin that isampniGampe a$oampt the state o 345
What are the amprocess states in Unix
As a rocess execamptes it chanes state accordin to itscircampmstances( Unix rocesses ha-e the olloin states9Rampnnin 9 The rocess is either rampnnin or it is read to rampn (aitin 9 The rocess is aitin or an e-ent or or a resoamprce(0toed 9 The rocess has $een stoed ampsampall $ recei-in asinal(om$ie 9 The 345
What is a gtombie
hen a roram orks and the child inishes $eore the arent
the kernel still kees some o its inormation a$oampt the child incase the arent miht need it or examle the arent maneed to check the childs exit statamps( To $e a$le to et thisinormation the arent calls Kait78= In the 345
How can a amparent and child amprocess communicate
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4756
A arent and child can commampnicate throamph an o the normalinterrocess commampnication schemes 7ies socketsmessae Gampeampes shared memor8 $ampt also ha-e some secialas to commampnicate that take ad-antae o their relationshias a arent and child( One o the most o$-ioamps is that the arent
can et the exit statamps o the 345
How can you getset an enironment ariable from aamprogram
Mettin the -alampe o an environment variable is done $ampsin Keten-78(0ettin the -alampe o an en-ironment -aria$le is done $ ampsinKampten-78(
-xamplain fork$ system call
The Kork78 ampsed to create a ne rocess rom an existinrocess( The ne rocess is called the child rocess and theexistin rocess is called the arent( e can tell hich is hich$ checkin the retamprn -alampe rom Kork78( The arent ets thechilds id retamprned to him $ampt 345
What are arious =s associated with a amprocess
Unix identiies each rocess ith a ampniGampe inteer called6rocessID( The rocess that execamptes the reGampest or creation
o a rocess is called the =arent rocess hose 6ID is =6arent6rocess ID( E-er rocess is associated ith a articamplar ampsercalled the =oner ho has ri-ilees o-er the rocess( Theidentiication or the ampser is 345
ltrief about the initial amprocess se9uence while the systemboots uamp
hile $ootin secial rocess called the saer orschedampler is created ith 6rocessID ( The saer manaesmemor allocation or rocesses and inlampences CPU allocation(The saer intamprn creates children9the rocess disatcher-hand and d$lampsh ith IDs F and resecti-el(This is done $ execamptin the ile etcinit( 6rocess disatcheri-es $irth to the shell( 345
What is a shell
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4856
A shell is an interactive user interface to an operatingsystem ser-ices that allos an ampser to enter commands ascharacter strins or throamph a graphical user interface(The shell con-erts them to sstem calls to the O0 or orks o arocess to execampte the command( 0stem call resamplts and other
inormation rom the O0 345
How does the inode maamp to data block of a file
Inode has $lock addresses( The irst are direct $lockaddresses o the irst data $locks in the ile( The thaddress oints to a onele-el index $lock( The Fth addressoints to a tole-el 7doamp$le indirection8 index $lock( The thaddress oints to a threele-el7trile indirection8index $lock(This ro-ides a -er lare maximampm 345
=iscuss the mount and unmount system calls
The ri-ileed moampnt sstem call is ampsed to attach a filesystem to a director o another ile sstem the ampnmoampntsstem call detaches a ile sstem( hen oamp moampnt another ilesstem on to oampr director oamp are essentiall slicin onedirector tree onto a $ranch in another director tree( The irstarampment to 345
How do you create sampecial files like named ampiampes and deice files
The sstem call mknod creates secial iles in the olloinseGampence(( kernel assins ne inodeF( sets the file type to indicate that the ile is a ie directoror secial ile( I it is a de-ice ile it makes the other entries like maor minorde-ice nampm$ers(ltor examle9 I the de-ice is a disk maor 345
What is a
ltIltO are otherise called as =named ies( ltIltO 7irstinirstoampt8 is a secial ile hich is said to $e data transient( Once datais read rom named ie it cannot $e read aain(
Also data can $e read onl in the order ritten( It is ampsed ininterrocess commampnication here a rocess rites to one endo 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 4956
5
What are links and symbolic links in UN file system
A link is a second name 7not a ile8 or a ile( Links can $e ampsedto assin more than one name to a ile $ampt cannot $e ampsed toassin a director more than one name or link ilenames on
dierent computers(0m$olic link =is a ile that onl contains the name o anotherile(Oeration 345
What are the Unix system calls for
oen7athnamelamode8 open filecreat7athnamemode8 create ileclose7iledes8 close an oen ileread7iledes$amper$tes8 read data rom an oen ilerite7iledes$amper$tes8 rite data to an oen ile
lseek7iledesosetrom8 osition an oen iledamp7iledes8 damplicate an existin ile descritor dampF7olddned8 damplicate to a desired ile descritor cntl7iledescmdar8 chane roerties o an oen ileioctl7iledesreGampestar8 chane the $eha-ioampr 345
ltrief about the directory reampresentation in UN
s a ile containin a corresondence $eteen ilenames andinodes( A director is a secial ile that the kernel maintains(Onl kernel modiies directories $ampt rocesses can read
directories( The contents o a director are a list o ilename andinode nampm$er airs( hen ne directories are created kernelmakes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile the
inode contains ointers 345
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5056
)7
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles are
named and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
ltrief about the directory reampresentation in UN
A Unix director is a ile containin a corresondence $eteenilenames and inodes( A director is a secial ile that the kernelmaintains( Onl kernel modiies directories $ampt rocesses canread directories( The contents o a director are a list oilename and inode nampm$er airs( hen ne directories are
created kernel makes to entries 345
What is inode0
All UNIX iles ha-e its descrition stored in a strampctampre called=inode( The inode contains ino a$oampt the ilesie its locationtime o last access time o last modiication ermission and soon( Directories are also reresented as iles and ha-e anassociated inode( In addition to descritions a$oampt the ile theinode contains ointers 345
How are deices reampresented in UN
All de-ices are reresented $ iles called secial iles that arelocated inde- director( Thamps de-ice iles and other iles arenamed and accessed in the same a( A =reamplar ile is ampst anordinar data ile in the disk( A =$lock secial ile reresents ade-ice ith characteristics similar to a disk 7data transer 345
How is the commandldquo$cat file2 ldquo differentfrom ldquo$cat gtfile2
Answer The Commond $cat file in unix is used to display the contentof the file and where as commond $cat gtgt file is to appendthe text to the end of the file without overwritting theinformation of the file Incase if the file does not exist in thedirectory the commond will create a newfile in file system
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5156
)1
$cat gtfile means to create a new file $cat file means to openan existing file
Answered By selvaravi Date 717
cat gt file it means creating file for file cat file it means used to
display the file content
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
xplain the steps thata shell follows whileprocessing a command
Answer
hen processing a command the searchs for the utility forthe command in the directories specified in the TH varileand it in invoes that utility That utility will execute thecommand with help of ernel and the output is given to shellnd then the displays out put to the user
hich command isused to delete all filesin the current directoryand all its suampdirectories
Answer
(rm ampfr )irectory namegt
( rm amprf +
Answered By Ait S$inis Date 1amp7
rm ampr +
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5256
)2
hat is the use of thecommand ls ampxchapter-amp0
Answer
1es you are correct It stands for listing the files Chapter withsuffix to ut it will display the files in columns as withampxoption
How does the erneldifferentiate devicefiles and ordinaryfiles
Answer
evice filles are of 2 types ampampamp charcater device file and locdevice file
type field in the files inode structure
ampampamp loc device file
campampamp character device file
How to switch to asuper user status togain privileges
Answer
3se 4su5 command The system ass for password and whenvalid entry is made the user gains super user 6admin7privileges
hat are shell variales
Answer 8hell variales are system environment varialesTheyinclude
T98Hltlt Ilt
the output of the shell variale we can see y typing thecommand
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5356
)3
$gtecho $T9
ansi
at the prompt
hat is redirection
Answer
9edirection is a feature in 3nix where the data from thestandard out put or a fileso oncan e redirected ie divert toa file or a program and vice versa
gt ampamp out put redirection
gtgt ampamp out put redirectin6appending at the last7
) ampamp input redirection
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process
8yntax ill pidill = amp ills all processes in your system except the loginshell
How to terminate aprocess which isrunning and thespecialty on commandill =
Answer
ith the help of ill command we can terminate the process8yntax ill pidill = amp ills all processes in your system except the loginshell
How to sfind freespace in unixlinux
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5456
)
Answer
f and du commands are used for checing free space on disdf amph or df ampHumanreadale gives human readale format offree space
hat is the differenceetween soft lin andhard lin in unixoperating system
Answer
Hard ltins
ll ltins have same inode numer
2ls ampl command shows all the lins with the lincolumn68econd7 shows Ao of lins
B ltins have actual file contents
9emoving any lin Dust reduces the lin count ut doesntaffect other lins
8oft ltins68ymolic ltins7
ltins have different inode numers
2 ls ampl command shows all lins with second column value and the lin points to original file
B ltin has the path for original file and not the contents
9emoving soft lin doesnt affect anything ut removingoriginal file the lin ecomes dangling lin which points tononexistant file
to concatenate6attach7 two strings
Answer
Eor concatenating two string we use cat command
xamp cat str str2
xplain the 3AIF
ernel
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5556
))
Answer
3AIF ernel is heart of the operating system 3AIF ernal isloaded first when 3AIF system is ooted It handles allocationof devices cpu memory from that ponint on
How many prompts areavailale in a 3AIFsystem
Answer
3nix ltinux 8upports four rompts 8 82 8B 8
(G$ are prompts
47747NC7S
Boo-s
1ampntroduction to U9amp N S8LL programming gt Men-atesh urth$ 4earson 8ducation
2Uni concepts and applications ourth 8dition Sumitabha Das
wjntuworldcom
wwwjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom
7232019 Unix Lab Manual JWFILES
httpslidepdfcomreaderfullunix-lab-manual-jwfiles 5656
)+
3Uni for programmers and users 3rd edition gtaham gtlass N F ltbles pearson education
Uni and shell 4rogramming Plt tet boo- Blt orou0an N gtiberg homson
)Beginning shell scripting 8 oster P ohnson N other ile Z ampndia
wjntuworldcom