You are on page 1of 56

1

INDEX

S.No
1 2 3 Lab Objective

Contents

Page No.
2 3 5 ) 1222 35 55

Introduction About Lab Guidelines to Students List o! S"llabus Progra#s $%N&'(

5 . . ) 3

*escri+tion about 'NI, co##ands *iscri+tion about s/ells Solutions !or Progra#s 0iva 1uestions and Ans2ers 4e!erences

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, for, while, until, and case. 3. Learn tracing mechanisms for debugging!, user "ariables, BourneShell "ariables, read#onl$ "ariables, positional parameters, reading input to a BourneShell script, command substitution, comments, and e%porting "ariables. &n addition, test on numeric "alues, test on file t$pe, and test on character strings are co"ered.
'. (op$, mo"e, and delete files and directories

). *rite moderatel$ comple% Shell scripts. +. ,a-e a Shell script e%ecutable. .. (reate a /.profile/ script to customi0e the user en"ironment. 1. Use ad"anced features of 2ile 3ransfer 4rotocol 234! 5. (ompile source code into ob6ect and e%ecutable modules. 17. 8%ecute programs written in c under U9&: en"ironment

INTRODUCTION ABOUT LAB

3here are ++ s$stems 3heir configurations are as follows : 4rocessor @<, ?ard Dis,ouse 9etwor- &nterface card : : : : :

(ompa; 4resario ! installed in this Lab.

<,D <thelon = 1.+. >?0 2)+ ,B '7 >B Aptical ,ouse

4resent

Software <ll s$stems are configured in DU<L BAA3 mode i.e, Students can boot from *indows :4 or Linu% as per their lab re;uirement. 3his is "er$ useful for students because the$ are familiar with different Aperating S$stems so that the$ can e%ecute their programs in different programming en"ironments. 8ach student has a separate login for database access Aracle 5i client "ersion is installed in all s$stems. An the ser"er, account for each student has been created. 3his is "er$ useful because students can sa"e their wor- scenariosB, plCs;l programs, data related pro6ects ,etc! in their own accounts. 8ach student wor- is safe and secure from other students. Latest 3echnologies li-e DA3 983 and D288 are installed in some s$stems. Before submitting their final pro6ect, the$ can start doing mini pro6ect from 2nd $ear onwards.

'

,<S, ,acro <ssembler ! is installed in all the s$stems Students can e%ecute their assembl$ language programs using ,<S,. ,<S, is "er$ useful students because when the$ e%ecute their programs the$ can see contents of 4rocessor @egisters and how each instruction is being e%ecuted in the (4U. @ational @ose Software is installed in some s$stems Using this software, students can depict U,L diagrams of their pro6ects. Softwares installed : (, (EE, DDF1.), ,<S,, A22&(8#:4, D288 and DA3 983, @ational @ose.

S$stems are pro"ided for students in the 1:1 ratio.

S$stems are assigned numbers and same s$stem is allotted for students when the$ do the lab.

Guidelines to Students
5o2 to 4un S/ell Scri+ts 3here are two wa$s $ou can e%ecute $our shell scripts. Ance $ou ha"e created a script file: ,ethod 1 4ass 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 2or e%ample, the script file show has the following lines echo ?ere is the date and time date Step 2 : 3o run the script, pass the filename as an argument to the sh shell ! G sh show ?ere is the date and time Sat 6un 73 13:'7:1) 4S3 277+

,ethod 2: ,a-e $our script e%ecutable using the chmod command. *hen we create a file, b$ default it is created with read and write permission turned on and e%ecute permission turned off. < file can be made e%ecutable using chmod. Step 1 : create the script using "i, e% or ed 2or e%ample, the script file show has the following lines echo ?ere is the date and time date Step 2 : ,a-e the file e%ecutable

G chmod uE% scriptHfile G chmod uE% show Step 3 : 3o run the script, 6ust t$pe the filename G show ?ere is the date and time Sat 6un 73 13:'7:1) 4S3 277+

5o2 to run C +rogra#s Step 1 : Use an editor, such as "i, e%, or ed to write the program. 3he name of the file containing the program should end in .c. 2or e%ample, the file show.c contains the following lines : main ! I printf J welcome to >98( J!K L Step 2 : Submit the file to (( the ( (ompiler ! G cc show.c &f the program is o-a$, the compiled "ersion is placed in a file called a.out Step 3 : 3o run the program, t$pe a.out G a.out *elcome to >98(

List of Lab Exercises S$llabus 4rograms D93U !


67781 Session 1 1. 2. 3. '. ). Log in to the s$stem Use Mi editor to create a file called m$file.t%t which contain some te%t. (orrect t$ping errors during creation Sa"e the file Logout of the file

Session 2 a! b! c! d! e! f! g! Log into the s$stem Apen the file created in session 1 <dd some te%t (hange some te%t delete some te%t Sa"e the changes 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 fields 1'2) ra"i 1).+) '327 ramu 2+.2. +137 sita 3+.1) 1')7 ra6u 21.1+ c! use the cat command to displa$ the file, m$ table d! use the "i command to correct an$ errors in the file, m$ table e! use the sort command to sort the file m$ table according to the first field. (all the sorted file m$ table same name! f! print the file m$ table g! use the cut N paste commands to swap fields 2 and 3 m$ table. (all it m$table same name! h! print the new file, m$ table i! logout of the s$stem

67783 a! b! c! d! e! a! b! c! log in the s$stem use the appropriate commands to determine ur login shell use the CetcCpasswd file to "erif$ the result of step b. use the who command redirect the result to a file called m$file1.Use the more command to see the contents of m$file1. Use the date and who commands in se;uence O in one line! such that the output of date will displa$ on the screen and the output of who will be redirected to a file called m$ file2.Use the more command to chec- the contents of m$file2. write a sed command that deletes the first character in each line in a file write a sed command that deletes the character before the last character in each line in a file. *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! De"elop an interacti"e grep script that as-s for a word and a file name and then tells how man$ lines contain that word c! @epeat d! 4art using aw67785 a! *rite < shell script that ta-es a command Pline argument and reports on whether it is directr$ ,a file,or something else b! *rite a shell script that accepts one or more file name as a arguments and con"erts all of thenm to uppercase,pro"ided the$ e%its in the current director$ c! *rite a shell script that determines the period for which a specified user is wor-ing on the s$stem 6778. a! write a shell script that accepts a file name starting and ending line numbers as arguments and displa$s all the lines between the gi"en line numbers b! write a shell script that deletes all lines containing a specified word & 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 the following 1! if basic salar$ is Q1)77 then ?@< 17R of the basic and D< S57R of the basic

5 2! if basic salar$ is T1)77 then ?@< )77 and D< S51R of the basic 3he basic salar$ is entered interacti"el$ through the -e$ board b! *rite a shell script that accepts two integers as its arguments and computes the "alue of first number raised to the power of the second number 6778 3 a! *rite an interacti"e file handling shell program. Let it offer the user the choice of cop$ing ,remo"ing ,renaming or lin-ing files. Ance the use has made a choice, ha"e the program as- the user for necessar$ information, such as the file name ,new name and so on. b! *rite a shell script that ta-es a login name as command Pline argument and reports when that person logs in c! *rite a shell script which recei"es two files names as arguments. &t should checwhether the two file contents are same or not. &f 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 which the user has read write and e%ecute permissions b! De"elop an interacti"e script that as-s for a word and file name and then tells how man$ times that word occurred in the file. c! *rite a shell script to perform the following string operations. 1! 3o e%tract a sub string from a gi"en string 2! 3o find the length of a gi"en string

*88F 17
*rite a ( program that ta-es one or more file or director$ names as command line input and reports the following information on the file. 1! file t$pe 2! number of lin-s 3! read, write and e%ecute permissions '! time of last access 9ote: use Cfstat s$stem calls!

*88F 11
*rite ( program that simulate the following uni% commands a! m" b! cp

17

*88F 12
*rite a c program that simulates ls command Use s$stem calls Cdirector$ <4&!

Basic Unix commands


(ommand S$nta% Description 8%amples (<3 cat UargumentV Uspecific fileV Jcat/ is short for concatenate. 3his command is used to create, "iew and concatenate files. cat CetcCpasswd 3his command displa$s the /CetcCpasswd/ file on $our screen. cat CetcCprofile 3his 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' 3his command combines the contents of the first three files into the fourth file.

(ommand S$nta%

pwd pwd

Description 8%amples

/pwd/ stands for print wor-ing director$. &t displa$s $our current position in the U9&: files$stem. pwd 3here are no options or arguments! with the /pwd/ command. &t is simpl$ used to report $our current wor-ing

11

(ommand S$nta%

director$. ls ls UoptionsV UnamesV

Description 8%amples

/ls/ stands for list. &t is used to list information about files and directories. ls 3his is the basic /ls/ command, with no options. &t pro"ides a "er$ basic listing of the files in $our current wor-ing director$. 2ilenames beginning with a decimal are considered hidden files, and the$ are not shown. ls #a 3he #a option tells the ls command to report information about all files, including hidden files. ls #l 3he #l option tells the /ls/ command to pro"ide a long listing of information about the files and directories it reports. 3he long listing will pro"ide important information about file permissions, user and group ownership, file si0e, and creation date. ls #al 3his command pro"ides a long listing of information about all files in the current director$. &t combines the functionalit$ of the #a and #l options. This is probably the most used version of the ls command. ls #al Cusr 3his command lists long information about all files in the /Cusr/ director$. ls #al@ Cusr W more 3his command lists long information about all files in the /Cusr/ director$, and all sub#directories of Cusr. 3he #@ option

12

tells the ls command to pro"ide a recursive listing of all files and sub#directories. ls #ld Cusr @ather than list the files contained in the Cusr director$, this command lists information about the Cusr director$ itself without generating a listing of the contents of Cusr!. 3his is "er$ useful when $ou want to chec- the permissions of the director$, and not the files the director$ contains.

(ommand S$nta% Aptions

m" m" UoptionsV sources target #b bac-up files that are about to be o"erwritten or remo"ed #i interacti"e modeK if dest e%ists, $ouXll be as-ed whether to o"erwrite the file 3he /m"/ command is used to mo"e and rename files. m" (hapter1 (hapter1.bad 3his command renames the file /(hapter1/ to the new name /(hapter1.bad/. m" (hapter1 garbage 3his command renames the file /(hapter1/ to the new name /garbage/. 9otice that if /garbage/ is a director$, /(hapter1/ would be mo"ed into that director$!. m" (hapter1 Ctmp 3his command mo"es the file /(hapter1/ into the director$ named /Ctmp/. m" tmp tmp.old <ssuming in this case that tmp is a director$, this e%ample renames the director$ tmp to the new name tmp.old. rm

Description 8%amples

(ommand

13 S$nta% Aptions rm UoptionsV files #d, ##director$ unlin- 2&L8, e"en if it is a non#empt$ director$ super#user onl$! #f, ##force ignore none%istent files, ne"er prompt #i, ##interacti"e prompt before an$ remo"al #r, #@, ##recursi"e remo"e the contents of directories recursi"el$ #", ##"erbose e%plain what is being done

Description 8%amples

3he /rm/ command is used to remo"e files and directories. *arning # be "er$ careful when remo"ing files and directoriesY! rm (hapter1.bad 3his command deletes the file named /(hapter1.bad/ assuming $ou ha"e permission to delete this file!. rm (hapter1 (hapter2 (hapter3 3his command deletes the files named /(hapter1/, /(hapter2/, and /(hapter3/. rm #i (hapter1 (hapter2 (hapter3 3his command prompts $ou before deleting an$ of the three files specified. 3he #i option stands for inquire. Zou must answer $ for $es! for each file $ou reall$ want to delete. 3his can be a safer wa$ to delete files. rm [.html 3his command deletes all files in the current director$ whose filename ends with the characters /.html/.

1'

rm inde%[ 3his command deletes all files in the current director$ whose filename begins with the characters /inde%/. rm #r new#no"el 3his command deletes the director$ named /new#no"el/. 3his director$, and all of itsX contents, are erased from the dis-, including an$ sub#directories and files.

(ommand S$nta%

cp cp UoptionsV file1 file2 cp UoptionsV files director$

Aptions

#b bac-up files that are about to be o"erwritten or remo"ed #i interacti"e modeK if dest e%ists, $ouXll be as-ed whether to o"erwrite the file #p preser"es the original fileXs ownership, group, permissions, and timestamp 3he /cp/ command is used to cop$ files and directories. 9ote that when using the cp command, $ou must alwa$s specif$ both the source and destination of the file s! to be copied.

Description

8%amples

cp .profile .profile.ba3his command copies $our /.profile/ to a file named /.profile.ba-/. cp CusrCfredC(hapter1 . 3his command copies the file named /(hapter1/ in the /CusrCfred/ director$ to the current director$. 3his e%ample assumes that $ou ha"e write permission in the current

1)

director$. cp CusrCfredC(hapter1 CusrCmar$ 3his command copies the /(hapter1/ file in /CusrCfred/ to the director$ named /CusrCmar$/. 3his e%ample assumes that $ou ha"e write permission in the /CusrCmar$/ director$. (ommand S$nta% grep grep UoptionsV regular e%pression UfilesV

Aptions match

#i #n #" #w

case#insensiti"e search show the line\ along with the matched line in"ert match, e.g. find all lines that do 9A3 match entire words, rather than substrings

Description 8%amples

3hin- of the /grep/ command as a /search/ command most people wish it was named /search/!. &t is used to search for te%t strings within one or more files. grep XfredX CetcCpasswd 3his command searches for all occurrences of the te%t string XfredX within the /CetcCpasswd/ file. &t will find and print on the screen! all of the lines in this file that contain the te%t string XfredX, including lines that contain usernames li-e /fred/ # and also /alfred/. grep X]fredX CetcCpasswd 3his command searches for all occurrences of the te%t string XfredX within the /CetcCpasswd/ file, but also re;uires that the /f/ in the name /fred/ be in the first column of each record thatXs what the caret character tells grep!. Using this more# ad"anced search, a user named /alfred/ would not be matched, because the letter /a/ will be in the first column. grep X6oeX [ 3his command searches for all occurrences of the te%t string

1+

X6oeX within all files of the current director$.

(ommand S$nta% Description 8%amples

m-dir m-dir UoptionsV director$ name 3he /m-dir/ command is used to create new directories sub#directories!. m-dir tmp 3his command creates a new director$ named /tmp/ in $our current director$. 3his e%ample assumes that $ou ha"e the proper permissions to create a new sub#director$ in $our current wor-ing director$.! m-dir memos letters e#mail 3his command creates three new sub#directories memos, letters, and e#mail! in the current director$. m-dir CusrCfredCtmp 3his command creates a new director$ named /tmp/ in the director$ /CusrCfred/. /tmp/ is now a sub#director$ of /CusrCfred/. 3his e%ample assumes that $ou ha"e the proper permissions to create a new director$ in CusrCfred.! m-dir #p ChomeC6oeCcustomerCacme 3his command creates a new director$ named ChomeC6oeCcustomerCacme, and creates an$ intermediate directories that are needed. &f onl$ ChomeC6oe e%isted to begin with, then the director$ /customer/ is created, and the director$ /acme/ is created inside of customer.

(ommand S$nta% Description

rmdir rmdir UoptionsV directories 3he /rm/ command is used to remo"e files and directories. *arning # be "er$ careful when remo"ing

1. files and directoriesY! rm (hapter1.bad 3his command deletes the file named /(hapter1.bad/ assuming $ou ha"e permission to delete this file!. rm (hapter1 (hapter2 (hapter3 3his command deletes the files named /(hapter1/, /(hapter2/, and /(hapter3/. rm #i (hapter1 (hapter2 (hapter3 3his command prompts $ou before deleting an$ of the three files specified. 3he #i option stands for inquire. Zou must answer $ for $es! for each file $ou reall$ want to delete. 3his can be a safer wa$ to delete files. rm [.html 3his command deletes all files in the current director$ whose filename ends with the characters /.html/. rm inde%[ 3his command deletes all files in the current director$ whose filename begins with the characters /inde%/. rm #r new#no"el 3his command deletes the director$ named /new#no"el/. 3his director$, and all of itsX contents, are erased from the dis-, including an$ sub#directories and files.

8%amples

(ommand S$nta%

cd, chdir cd Uname of director$ $ou want to mo"e toV

Description 8%amples

/cd/ stands for change director$. &t is the primar$ command for mo"ing around the files$stem. cd Cusr

11

3his command mo"es $ou to the /Cusr/ director$. /Cusr/ becomes $our current wor-ing director$. cd CusrCfred ,o"es $ou to the /CusrCfred/ director$. cd Cu[Cf[ ,o"es $ou to the /CusrCfred/ director$ # if this is the onl$ director$ matching this wildcard pattern. cd &ssuing the /cd/ command without an$ arguments mo"es $ou to $our home director$. cd # Using the Forn shell, this command mo"es $ou bac- to $our pre"ious wor-ing director$. 3his is "er$ useful when $ouXre in the middle of a pro6ect, and -eep mo"ing bac-#and#forth between two directories.

(ommand S$nta% Description

-ill -ill UoptionsV &Ds -ill ends one or more process &Ds. &n order to do this $ou must own the process or be designated a pri"ileged user. 3o find the process &D of a certain 6ob use ps.

8%amples (ommand S$nta% Description ps ps UoptionsV 3he /ps/ command process statistics! lets $ou checthe status of processes that are running on $our Uni%

15 s$stem. ps 3he ps command b$ itself shows minimal information about the processes you are running. *ithout an$ arguments, this command will not show information about other processes running on the s$stem. ps #f 3he #f argument tells ps to suppl$ full information about the processes it displa$s. &n this e%ample, ps displa$s full information about the processes you are running. ps #e 3he #e argument tells the ps command to show every process running on the s$stem. ps #ef 3he #e and #f arguments are normall$ combined li-e this to show full information about e"er$ process running on the s$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 output of the ps #ef command is often piped into the more command. 3he more command lets $ou "iew one screenful of information at a time. ps #fu fred 3his command shows full information about the processes currentl$ being run b$ the user named fred the #u option lets $ou specif$ a username!.

8%amples

27

6/" 'se S/ells:


*ell, most li-el$ because the are a simple wa$ to string together a bunch of U9&: commands for e%ecution at an$ time without the need for prior compilation. <lso because its generall$ fast to get a script going. 9ot forgetting the ease with which other scripters can read the code and understand what is happening. Lastl$, the$ are generall$ completel$ portable across the whole U9&: world, as long as the$ ha"e been written to a common standard.

&/e S/ell 5istor";


3he basic shells come in three main language forms. 3hese are in order of creation! s/< cs/ and =s/. Be aware that there are se"eral dialects of these script languages which tend to ma-e them all slightl$ platform specific. *here these differences are -nown to cause difficulties & ha"e made special notes within the te%t to highlight this fact. 3he different dialects are due, in the main, to the different U9&: fla"ours in use on some platforms. <ll script languages though ha"e at their heart a common core which if used correctl$ will guarantee portabilit$.

>ourne S/ell;
?istoricall$ the s/ language was the first to be created and goes under the name of 3he Bourne Shell. &t has a "er$ compact s$nta% which ma-es it obtuse for no"ice users but "er$ efficient when used b$ e%perts. &t also contains some powerful constructs built in. An U9&: s$stems, most of the scripts used to start and configure the operating s$stem are written in the Bourne shell. &t has been around for so long that is it "irtuall$ bug free. & ha"e adopted the Bourne shell s$nta% as the defacto standard within this boo-.

C S/ell;
9e%t up was 3he ( Shell cs/!, so called because of the similar s$ntactical structures to the ( language. 3he U9&: man pages contain almost twice as much information for the ( Shell as the pages for the Bourne shell, leading most users to belie"e that it is twice as good. 3his is a shame because there are se"eral compromises within the ( Shell which

21 ma-es using the language for serious wor- difficult chec- the list of bugs at the end of the man pagesY!. 3rue, there are so man$ functions a"ailable within the ( Shell that if one should fail another could be found. 3he point is do $ou really want to spend $our time finding all the alternati"e wa$s of doing the same thing 6ust to -eep $ourself out of trouble. 3he real reason wh$ the ( Shell is so popular is that it is usuall$ selected as the default login shell for most users. 3he features that guarantee its continued use in this arena are aliases, and histor$ lists. 3here are rumours howe"er, that ( Shell is destined to be phased out, with future U9&: releases onl$ supporting s/ and =s/. Differences between cs/ and s/ s$nta% will be highlighted where appropriate.

22

8orne S/ell;
Lastl$ we come to 3he Forne Shell =s/! made famous b$ &B,Xs <&: fla"our of U9&:. 3he 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. 3he e%tensions o"er and abo"e the Bourne shell e%ceed e"en the le"el of functionalit$ a"ailable within the ( Shell but without an$ of the compromisesY!, ma-ing it the ob"ious language of choice for real scripters. ?owe"er, because not all platforms are $et supporting the Forne shell it is not fully portable as a scripting language at the time of writing. 3his ma$ change howe"er 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%. 4erse"ere, it will pa$ off e"entuall$. <n$ s/ s$nta% element will wor- in the =s/ without change.

23 SOL'&IONS; 67781 Session 1 1. Log in to t/e s"ste# 2. 'se 0i editor to create a !ile called #"!ile.t?t 2/ic/ contain so#e te?t. 3. Correct t"+ing errors during creation . Save t/e !ile 5. Logout o! t/e !ile Sol: G login: Quser nameT G password: [[[[[[ G "i ^ Uni% is (ase Sensiti"e ^ 9e"er lea"e the (omputer without logging out when $ou are wor-ing in a time sharing or networ- en"ironments. 3$pe Q8scT : w; m$file G Session 2 1. 2. 3. . 5. .. ). Sol: G login: Quser nameT G password: [[[[[[ G "i m$file ^ Uni% is (ase Sensiti"e ^ 9e"er lea"e the (omputer without logging out when $ou are wor-ing in a time sharing or networ- en"ironments. ^ Shell 4rogramming : w; Log into t/e s"ste# O+en t/e !ile created in session 1 Add so#e te?t C/ange so#e te?t delete so#e te?t Save t/e c/anges Logout o! t/e s"ste#

2' 67782 Log into t/e s"ste# 'se t/e cat co##and to create a !ile containing t/e !ollo2ing data. Call it #utable use tabs to se+arate t/e !ields 1 25 32.331 5ravi ra#u sita raju 15..5 2..2) 3..15 21.3.

a. use t/e cat co##and to dis+la" t/e !ile< #" table b. use t/e vi co##and to correct an" errors in t/e !ile< #" table c. use t/e sort co##and to sort t/e !ile #" table according to t/e !irst !ield. Call t/e sorted !ile #" table$sa#e na#e( d. +rint t/e !ile #" table e. use t/e cut @ +aste co##ands to s2a+ !ields 2 and 3 #" table. Call it #"table$sa#e na#e( !. +rint t/e ne2 !ile< #" table g. logout o! t/e s"ste# Sol: G login: Quser nameT G password:[[[[[[ G cat Pc1#1' 1'2) QtabT ra"i QtabT '327 QtabT ramu QtabT +137 QtabT sita QtabT 1')7 QtabT ra6u QtabT G cat m$file GwhoWmore G sort E7 #1 m$table 1).+) QtabT 2+.2. QtabT 3+.1) QtabT 21.1+ QtabT

2)

67783 a. b. c. d. e. log in t/e s"ste# use t/e a++ro+riate co##ands to deter#ine ur login s/ell use t/e AetcA+ass2d !ile to veri!" t/e result o! ste+ b. use t/e 2/o co##and redirect t/e result to a !ile called #"!ile1.'se t/e #ore co##and to see t/e contents o! #"!ile1. 'se t/e date and 2/o co##ands in seBuence :$in one line( suc/ t/at t/e out+ut o! date 2ill dis+la" on t/e screen and t/e out+ut o! 2/o 2ill be redirected to a !ile called #" !ile2.'se t/e #ore co##and to c/ec= t/e contents o! #"!ile2. 2rite a sed co##and t/at deletes t/e !irst c/aracter in eac/ line in a !ile 2rite a sed co##and t/at deletes t/e c/aracter be!ore t/e last c/aracter in eac/ line in a !ile. 6rite a sed co##and t/at s2a+s t/e !iles and second 2ords in eac/ line in a !ile

!. g. /.

Sol: G login: Quser nameT G password:[[[[[[ G echo GS?8LL csh G who TW m$file1 G more m$file1 G dateWwho Tm$file2 G more m$file2

2+ 6778 +i+e ur AetcA+ass2d !ile to a2= and +rint out t/e /o#e director" o! eac/ user. *evelo+ an interactive gre+ scri+t t/at as=s !or a 2ord and a !ile na#e and t/en tells /o2 #an" lines contain t/at 2ord 4e+eat Part using a2= $d( Sol; G aw- _G2 SS`(omputers` NN G3 T17777 IprintLBSales.dat IAP; 1 1 1 2 2 2 2 OAP; 2 (omputers 1232 (lothing 31'1 (omputers 51+1 3e%tboo-s 21312 (lothing 32)2 (omputers 1232 Supplies 22'2 3e%t boo-s 1)'+2

2.

67785 a( 6rite A s/ell scri+t t/at ta=es a co##and Cline argu#ent and re+orts on 2/et/er it is directr" <a !ile<or so#et/ing else b( 6rite a s/ell scri+t t/at acce+ts one or #ore !ile na#e as a argu#ents and converts all o! t/en# to u++ercase<+rovided t/e" e?its in t/e current director" c( 6rite a s/ell scri+t t/at deter#ines t/e +eriod !or 2/ic/ a s+eci!ied user is 2or=ing on t/e s"ste#

$a( Sol; echo /8nter a file name:/ read f if U #f Gf V then echo /2ile/ elif U #d Gf V then echo /Director$/ else echo /9ot/ fi

Out+ut; Director$

21 6778. $a( 6rite a s/ell scri+t t/at acce+ts a !ile na#e starting and ending line nu#bers as argu#ents and dis+la"s all t/e lines bet2een t/e given line nu#bers $b( 6rite a s/ell scri+t t/at deletes all lines containing a s+eci!ied 2ord I one or #ore !iles su++lied as argu#ents to it.

$a( Sol; G aw- _9@Q2 WW 9@T ' Iprint G7LB ) lines.dat &C4: line1 line2 line3 line' line) line1 line)

AC4:

$b( Sol; iS1 while U Gi #le G\ V do grep #" Uni% Gi T Gi done

25 6778) a( 6rite a s/ell scri+t t/at co#+utes t/e gross salar" o! a e#+lo"ee according to t/e !ollo2ing 1( i! basic salar" is D15-- t/en 54A 1-E o! t/e basic and *A F9-E o! t/e basic 2( i! basic salar" is G15-- t/en 54A 5-- and *A F93E o! t/e basic &/e basic salar" is entered interactivel" t/roug/ t/e =e" board $b(6rite a s/ell scri+t t/at acce+ts t2o integers as its argu#ents and co#+utes t/e value o! !irst nu#ber raised to t/e +o2er o! t/e second nu#ber echo / 8nter the Salar$ / read sal if U GsalQ1)77V then daSae%pr Gsal[57C177a hraSae%pr Gsal[17C177a gsalSBe%pr Gsal EGhraEGda echo JGgsal` elif UGsalT1)77V hraS)77 daSBe%pr Gsal[51C177B gsalSBe%pr GsalEGhraEGda grossSae%pr Gsa E Gda E Ghraa fi fi b! aSG1 bSG2 cSpow Ga,Gb! echo`Gc`

37

6778 3 $a( 6rite an interactive !ile /andling s/ell +rogra#. Let it o!!er t/e user t/e c/oice o! co+"ing <re#oving <rena#ing or lin=ing !iles. Once t/e use /as #ade a c/oice< /ave t/e +rogra# as= t/e user !or necessar" in!or#ation< suc/ as t/e !ile na#e <ne2 na#e and so on. $b( 6rite a s/ell scri+t t/at ta=es a login na#e as co##and Cline argu#ent and re+orts 2/en t/at +erson logs in $c( 6rite a s/ell scri+t 2/ic/ receives t2o !iles na#es as argu#ents. It s/ould c/ec= 2/et/er t/e t2o !ile contents are sa#e or not. I! t/e" are sa#e t/en second !ile s/ould be deleted.

P4OG4AH echo /8nter & 2ile 9ame:/ read f1 echo /8nter && 2ile 9ame:/ read f2 dSacmp Gf1 Gf2a d1S// if U Gd #e; Gd2 V then echo /3wo 2iles are similar and Gf2 is deleted/ rm Gf2 else echo /3wo 2iles differ each other/ fi

31 6778 9 $a( 6rite a s/ell scri+t t/at dis+la"s a list o! all !iles in t/e current director" to 2/ic/ t/e user /as read 2rite and e?ecute +er#issions $b( *evelo+ an interactive scri+t t/at as=s !or a 2ord and !ile na#e and t/en tells /o2 #an" ti#es t/at 2ord occurred in t/e !ile. $c( 6rite a s/ell scri+t to +er!or# t/e !ollo2ing string o+erations. 1( &o e?tract a sub string !ro# a given string 2( &o !ind t/e lengt/ o! a given string $a( P4OG4AH \ 2ile 9ame : list.sh \YCbinCbash read #p /8nter a director$ name : / dn if U #d Gdn VK then printf /bn2iles in the director$ Gdn are :bn/ for fn in als Gdna do if U #d GdnCGfn VK then printf /QGfnT Director$ / elif U #f GdnCGfn V then printf /Gfn 2ile / fi if U #r GdnCGfn VK then printf / @ead/ fi if U #w GdnCGfn VKthen printf / *rite/ fi if U #% GdnCGfn VKthen printf / 8%ecute/ fi printf /bn/ done else printf /bnGdn not e%ists or not a director$/ fi

32

$b( P4OG4AH \ 2ile 9ame : wcount.sh \YCbinCbash read #p /8nter a file name : / fn if test #f Gfn then echo /3he contents of the file Gfn is :/ cat Gfn echo /9o. of Line : awc #l Gfna/ echo /9o. of *ords : awc #w Gfna/ echo /9o. of (haracters: awc #c Gfna/ else echo /Gfn is not e%ists or not a file/ fi $c( P4OG4AH 4rint J8nter the String:bc` read str&n strlenSGI\ str&nL print the string length is : Gstrlen G strlen.scr AC4: 8nter the String: 9ow is the time 3he String length : 1)

33

*88F 17
6rite a C +rogra# t/at ta=es one or #ore !ile or director" na#es as co##and line in+ut and re+orts t/e !ollo2ing in!or#ation on t/e !ile. 1. 2. 3. '. file t$pe number of lin-s read, write and e%ecute permissions time of last access

9ote: use Cfstat s$stem calls! P4OG4AH \includeQstdio.hT main ! I 2&L8 [streamK int bufferHcharacterK streamSfopen Jtest`,`r`!K if streamSS 2&L8[!7! I fprintf stderr,`8rror opening file printed to standard error!bn`!K fclose stream!K e%it 1!K L L if fclose stream!!SS8A2! I fprintf stderr,`8rror closing stream. printed to standard error!bn!K e%it 1!K L return !K L

3'

*88F 11
6rite C +rogra# t/at si#ulate t/e !ollo2ing uni? co##ands $a( #v $b( c+ C[ 2ile 9ame : bspace1.c [C \includeQfcntl.hT \includeQunistd.hT \includeQstdio.hT main int argc,char [arg"UV! I 2&L8 [fpK char chK int scS7K fpSfopen arg"U1V,/r/!K if fpSS9ULL! printf /unable to open a file/,arg"U1V!K else I while Yfeof fp!! I chSfgetc fp!K if chSSX X! scEEK L printf /no of spaces Rd/,sc!K printf /bn/!K fclose fp!K L L

3)

*88F 12
6rite a c +rogra# t/at si#ulates ls co##and $'se s"ste# calls Adirector" API( P4OG4AH; \includeQstdio.hT \includeQfcntl.hT \includeQstdlib.hT main int argc,char [arg"UV! I int fd,iK char chU1VK if argcQ2! I printf /Usage: m$cat filenamebn/!K e%it 7!K L fdSopen arg"U1V,AH@DA9LZ!K if fdSS#1! printf /Rs is not e%ist/,arg"U1V!K else I printf /(ontents of the file Rs is : bn/,arg"U1V!K while read fd,ch,1!T7! printf /Rc/,chU7V!K close fd!K L

3+

0iva 1uestions @ Ans2ers


What is a Make file?
,a-e file is a utilit$ in Unix to help compile large programs. &t helps b$ onl$ compiling the 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! it"s res#onsi$le or controllin% the com#&ter"s reso&rces and sched&lin% &ser 'o$s so that each one %ets its air share o reso&rces(

How can you tell what shell you are running on UN ! system?
)o& can do the Echo *RANDO+( It ,ill ret&rn a &nde ined -aria$le i .o& are rom the C/0hell! '&st a ret&rn #rom#t i .o& are rom the Bo&rne shell! and a 1 di%it random n&m$ers i .o& are rom the 2orn shell( )o& co&ld also do a #s /l and look or the shell ,ith 345

What do you mean by u"area #user area$ or u"block?


This contains the #ri-ate data that is mani#&lated onl. $. the 2ernel( This is local to the 6rocess! i(e( each #rocess is allocated a &/area(

What scheme does the Kernel in Unix System % follow while choosing a swa& de'ice among the multi&le swa& de'ices?
2ernel ollo,s Ro&nd Ro$in scheme choosin% a s,a# de-ice amon% the m&lti#le s,a# de-ices in Unix System V(

(ist the system calls used for &rocess management)


0.stem calls ork78 exec78 ,ait78 345 Descri#tion To create a ne, #rocess To exec&te a ne, #ro%ram in a #rocess

3.

How do you change *ile +ccess ,ermissions?


E-er. ile has ollo,in% attri$&tes9 o,ner"s user ID 7 :; $it inte%er 8 o,ner"s %ro&# ID 7 :; $it inte%er 8 <ile access mode ,ord =r , x /r , x/ r , x" 7&ser #ermission/%ro&# #ermission/others #ermission8 r/read! ,/,rite! x/exec&te To chan%e the access mode! ,e &se chmod7 ilename!mode8( Exam#le9 To chan%e mode o m. ile to =r,/r,/r>" 7ie( read! ,rite #ermission or &ser / 345

-x&lain the layered as&ect of a UN ! system. What are the layers? What does it mean to say they are layers?
A UNIX system has essentiall. three main la.ers9 ( The hard,are ( The operating system kernel ( The &ser/le-el #ro%rams The kernel hides the s.stem"s hard,are &nderneath an a$stract! hi%h/le-el #ro%rammin% inter ace( It is res#onsi$le or im#lementin% man. o the acilities that &sers and &ser/le-el #ro%rams take or %ranted( The kernel assem$les all o the ollo,in% UNIX conce#ts rom lo,er/le-el 345

What is the use of /gre&0 command?


=%re#" is a #attern search command( It searches or the #attern! s#eci ied in the command line ,ith a##ro#riate o#tion! in a ile7s8( 0.ntax 9 %re# Exam#le 9 %re# ??mx mca ile

What difference between cm& and diff commands?


cm# / Com#ares t,o iles $.te $. $.te and dis#la.s the irst mismatch di / tells the chan%es to $e made to make the iles identical

What is the significance of the 1tee2 command?

31 It reads the standard in#&t and sends it to the standard o&t#&t ,hile redirectin% a co#. o ,hat it has read to the ile s#eci ied $. the &ser(

s /du0 a command? f so3 what is its use?


)es! it stands or =disk &sa%e"( @ith the hel# o this command .o& can ind the disk ca#acit. and free space o the disk(

How to terminate a &rocess which is running and the s&ecialty on command kill 4?
@ith the hel# o kill command ,e can terminate the #rocess( 0.ntax9 kill #id 2ill A / kills all #rocesses in .o&r s.stem exce#t the lo%in shell(

35

-x&lain kill#$ and its &ossible return 'alues.


There are o&r #ossi$le res&lts rom this call9 =kill78" ret&rns A( This im#lies that a #rocess exists ,ith the %i-en 6ID! and the s.stem ,o&ld allo, .o& to send si%nals to it( It is s.stem/de#endent ,hether the #rocess co&ld $e a Bom$ie( =kill78" ret&rns /:! =errno CC E0RCD" either no #rocess exists ,ith the %i-en 6ID! or 345

What does the command 1 5who 6 sort 7logfile 8 newfile2 do?


The in#&t rom a #i#e can $e com$ined ,ith the in#&t rom a ile ( The trick is to &se the s#ecial s.m$ol E/E 7a h.#hen8 or those commands that reco%niBe the h.#hen as std in#&t( In the a$o-e command the o&t#&t rom ,ho $ecomes the std in#&t to sort ! mean,hile sort o#ens the ile 345

What are shell 'ariables?


0hell -aria$les are s#ecial -aria$les! a name/-al&e #air created and maintained $. the shell( Exam#le9 6ATD! DO+E! +AIL and TER+

How many &rom&ts are a'ailable in a UN ! system?


T,o #rom#ts! 60: 76rimar. 6rom#t8! 60F 70econdar. 6rom#t8(

s it &ossible to create new a file system in UN !?


Use =s&" command( The s.stem asks or #ass,ord and ,hen -alid entr. is made the &ser %ains s&#er &ser 7admin8 #ri-ile%es(

How the Kernel handles the co&y on write bit of a &age3 when the bit is set?
In sit&ations like! ,here the co#. on ,rite $it o a #a%e is set and that #a%e is shared $. more than one #rocess! the 2ernel allocates ne, #a%e and co#ies the content to the ne, #a%e and the other #rocesses retain their re erences to the old #a%e( A ter co#.in% the 2ernel &#dates the #a%e 345

*i!!erence bet2een t/e !or=$( and v!or=$( s"ste# call:

'7 During the for- ! s$stem call the Fernel ma-es a cop$ of the parent processBs address space and attaches it to the child process.But the "for- ! s$stem call do not ma-es an$ cop$ of the parentBs address space, so it is faster than the for- ! s$stem call. 3he child process as a result of the "for- ! UcV

How the Kernel handles the fork#$ system call in traditional Unix and in the System % Unix3 while swa&&ing?
2ernel in traditional Unix! makes the d&#licate co#. o the #arent"s address s#ace and attaches it to the child"s #rocess! ,hile s,a##in%( 2ernel in 0.stem V Unix! mani#&lates the re%ion ta$les! #a%e ta$le! and # data ta$le entries! $. incrementin% the re erence co&nt o the re%ion ta$le o shared re%ions(

What are the re9uirements for a swa&&er to work?


The s,a##er ,orks on the hi%hest sched&lin% #riorit.( <irstl. it ,ill look or an. slee#in% #rocess! i not o&nd then it ,ill look or the read./to/r&n #rocess or s,a##in%( B&t the ma'or reG&irement or the s,a##er to ,ork the read./to/r&n #rocess m&st $e core/resident or at least F seconds $e ore s,a##in% o&t( And or s,a##in% 345

What is -x&ansion swa&?


At the time ,hen an. #rocess reG&ires more memor. than it is c&rrentl. allocated! the 2ernel #er orms Ex#ansion s,a#( To do this 2ernel reser-es eno&%h s#ace in the s,a# de-ice( Then the address translation ma##in% is ad'&sted or the ne, -irt&al address s#ace $&t the #h.sical memor. is not allocated( At last 2ernel s,a#s the 345

What is *ork swa&?


ork78 is a s.stem call to create a child #rocess( @hen the #arent #rocess calls ork78 s.stem call! the child #rocess is created and i there is short o memor. then the child #rocess is sent to the read/to/r&n state in the s,a# de-ice! and ret&rn to the &ser state ,itho&t s,a##in% the #arent #rocess( 345

What are the entities that are swa&&ed out of the main memory while swa&&ing the &rocess out of the main memory?

'1 All memor. s#ace occ&#ied $. the #rocess! #rocess"s &/area! and 2ernel stack are s,a##ed o&t! theoreticall.( 6racticall.! i the #rocess"s &/area contains the Address Translation Ta$les or the #rocess then 2ernel im#lementations do not s,a# the &/area(

s the ,rocess before and after the swa& are the same? :i'e reason.
6rocess $e ore s,a##in% is residin% in the #rimar. memor. in its ori%inal orm( The re%ions 7text! data and stack8 ma. not $e occ&#ied &ll. $. the #rocess! there ma. $e e, em#t. slots in an. o the re%ions and ,hile s,a##in% 2ernel do not $other a$o&t the em#t. slots ,hile s,a##in% the #rocess o&tA ter s,a##in% 345

What are the e'ents done by the Kernel after a &rocess is being swa&&ed out from the main memory?
@hen 2ernel s,a#s the #rocess o&t o the #rimar. memor.! it #er orms the ollo,in%9 2ernel decrements the Re erence Co&nt o each re%ion o the #rocess( I the re erence co&nt $ecomes Bero! s,a#s the re%ion o&t o the main memor.( 2ernel allocates the s#ace or the s,a##in% #rocess in the s,a# de-ice( 2ernel locks the other s,a##in% #rocess ,hile 345

What is ma;or difference between the Historic Unix and the new <S= release of Unix System % in terms of Memory Management?
Distoric Unix &ses 0,a##in% > entire #rocess is trans erred to the main memor. rom the s,a# de-ice! ,hereas the Unix 0.stem V &ses Demand 6a%in% > onl. the #art o the #rocess is mo-ed to the main memor.( Distoric Unix &ses one 0,a# De-ice and Unix 0.stem V allo, m&lti#le 0,a# De-ices

What is an ad'antage of executing a &rocess in background?


The most common reason to #&t a #rocess in the $ack%ro&nd is to allo, .o& to do somethin% else interacti-el. ,itho&t ,aitin% or the #rocess to com#lete( At the end o the command .o& add the s#ecial $ack%ro&nd s.m$ol! H( This s.m$ol tells .o&r shell

'2 to exec&te the %i-en command in the $ack%ro&nd( Exam#le9 c# I(I 345

What Ha&&ens when you execute a &rogram?


@hen .o& exec&te a #ro%ram on .o&r UNIX s.stem! the s.stem creates a s#ecial en-ironment or that #ro%ram( This en-ironment contains e-er.thin% needed or the s.stem to r&n the #ro%ram as i no other #ro%ram ,ere r&nnin% on the s.stem( Each #rocess has #rocess context! ,hich is e-er.thin% that is &niG&e a$o&t the state o 345

What are the &rocess states in Unix?


As a #rocess exec&tes it chan%es state accordin% to its circ&mstances( Unix #rocesses ha-e the ollo,in% states9 R&nnin% 9 The #rocess is either r&nnin% or it is read. to r&n ( @aitin% 9 The #rocess is ,aitin% or an e-ent or or a reso&rce( 0to##ed 9 The #rocess has $een sto##ed! &s&all. $. recei-in% a si%nal( Jom$ie 9 The 345

'3

What is a >ombie?
@hen a #ro%ram orks and the child inishes $e ore the #arent! the kernel still kee#s some o its in ormation a$o&t the child in case the #arent mi%ht need it / or exam#le! the #arent ma. need to check the child"s exit stat&s( To $e a$le to %et this in ormation! the #arent calls K,ait78=L In the 345

How can a &arent and child &rocess communicate?


A #arent and child can comm&nicate thro&%h an. o the normal inter/#rocess comm&nication schemes 7#i#es! sockets! messa%e G&e&es! shared memor.8! $&t also ha-e some s#ecial ,a.s to comm&nicate that take ad-anta%e o their relationshi# as a #arent and child( One o the most o$-io&s is that the #arent can %et the exit stat&s o the 345

How can you get?set an en'ironment 'ariable from a &rogram?


Mettin% the -al&e o an en-ironment -aria$le is done $. &sin% K%eten-78"( 0ettin% the -al&e o an en-ironment -aria$le is done $. &sin% K#&ten-78"(

-x&lain fork#$ system call.


The K ork78" &sed to create a ne, #rocess rom an existin% #rocess( The ne, #rocess is called the child #rocess! and the existin% #rocess is called the #arent( @e can tell ,hich is ,hich $. checkin% the ret&rn -al&e rom K ork78"( The #arent %ets the child"s #id ret&rned to him! $&t 345

What are 'arious =s associated with a &rocess?


Unix identi ies each #rocess ,ith a &niG&e inte%er called 6rocessID( The #rocess that exec&tes the reG&est or creation o a #rocess is called the =#arent #rocess" ,hose 6ID is =6arent 6rocess ID"( E-er. #rocess is associated ,ith a #artic&lar &ser called the =o,ner" ,ho has #ri-ile%es o-er the #rocess( The identi ication or the &ser is 345

<rief about the initial &rocess se9uence while the system boots u&.

'' @hile $ootin%! s#ecial #rocess called the "s,a##er" or "sched&ler" is created ,ith 6rocess/ID A( The s,a##er mana%es memor. allocation or #rocesses and in l&ences C6U allocation( The s,a##er int&rn creates N children9 the #rocess dis#atcher!-hand and d$ l&sh ,ith IDs :!F and N res#ecti-el.( This is done $. exec&tin% the ile OetcOinit( 6rocess dis#atcher %i-es $irth to the shell( 345

')

What is a shell?
A shell is an interacti-e &ser inter ace to an o#eratin% s.stem ser-ices that allo,s an &ser to enter commands as character strin%s or thro&%h a %ra#hical &ser inter ace( The shell con-erts them to s.stem calls to the O0 or orks o a #rocess to exec&te the command( 0.stem call res&lts and other in ormation rom the O0 345

How does the inode ma& to data block of a file?


Inode has :N $lock addresses( The irst :A are direct $lock addresses o the irst :A data $locks in the ile( The ::th address #oints to a one/le-el index $lock( The :Fth address #oints to a t,o/le-el 7do&$le in/direction8 index $lock( The :Nth address #oints to a three/le-el7tri#le in/direction8index $lock( This #ro-ides a -er. lar%e maxim&m 345

=iscuss the mount and unmount system calls


The #ri-ile%ed mo&nt s.stem call is &sed to attach a ile s.stem to a director. o another ile s.stemL the &nmo&nt s.stem call detaches a ile s.stem( @hen .o& mo&nt another ile s.stem on to .o&r director.! .o& are essentiall. s#licin% one director. tree onto a $ranch in another director. tree( The irst ar%&ment to 345

How do you create s&ecial files like named &i&es and de'ice files?
The s.stem call mknod creates s#ecial iles in the ollo,in% seG&ence( :( kernel assi%ns ne, inode! F( sets the ile t.#e to indicate that the ile is a #i#e! director. or s#ecial ile! N( I it is a de-ice ile! it makes the other entries like ma'or! minor de-ice n&m$ers( <or exam#le9 I the de-ice is a disk! ma'or 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 &sed to assi%n more than one name to a ile! $&t cannot $e &sed to assi%n a director. more than one name or link ilenames on di erent com#&ters(

'+ 0.m$olic link =is" a ile that onl. contains the name o another ile(O#eration 345

What are the Unix system calls for ?@?


o#en7#athname! la%!mode8 / o#en ile creat7#athname!mode8 / create ile close7 iledes8 / close an o#en ile read7 iledes!$& er!$.tes8 / read data rom an o#en ile ,rite7 iledes!$& er!$.tes8 / ,rite data to an o#en ile lseek7 iledes!o set! rom8 / #osition an o#en ile d&#7 iledes8 / d&#licate an existin% ile descri#tor d&#F7old d!ne, d8 / d&#licate to a desired ile descri#tor cntl7 iledes!cmd!ar%8 / chan%e #ro#erties o an o#en ile ioctl7 iledes!reG&est!ar%8 / chan%e the $eha-io&r 345

What Ha&&ens when you execute a &rogram?


@hen .o& exec&te a #ro%ram on .o&r UNIX system! the s.stem creates a s#ecial en-ironment or that #ro%ram( This en-ironment contains e-er.thin% needed or the s.stem to r&n the #ro%ram as i no other #ro%ram ,ere r&nnin% on the s.stem( Each #rocess has #rocess context! ,hich is e-er.thin% that is &niG&e a$o&t the state o 345

What are the &rocess states in Unix?


As a #rocess exec&tes it chan%es state accordin% to its circ&mstances( Unix #rocesses ha-e the ollo,in% states9 R&nnin% 9 The #rocess is either r&nnin% or it is read. to r&n ( @aitin% 9 The #rocess is ,aitin% or an e-ent or or a reso&rce( 0to##ed 9 The #rocess has $een sto##ed! &s&all. $. recei-in% a si%nal( Jom$ie 9 The 345

What is a >ombie?
@hen a #ro%ram orks and the child inishes $e ore the #arent! the kernel still kee#s some o its in ormation a$o&t the child in case the #arent mi%ht need it / or exam#le! the #arent ma. need to check the child"s exit stat&s( To $e a$le to %et this in ormation! the #arent calls K,ait78=L In the 345

How can a &arent and child &rocess communicate?

'. A #arent and child can comm&nicate thro&%h an. o the normal inter/#rocess comm&nication schemes 7#i#es! sockets! messa%e G&e&es! shared memor.8! $&t also ha-e some s#ecial ,a.s to comm&nicate that take ad-anta%e o their relationshi# as a #arent and child( One o the most o$-io&s is that the #arent can %et the exit stat&s o the 345

How can you get?set an en'ironment 'ariable from a &rogram?


Mettin% the -al&e o an environment variable is done $. &sin% K%eten-78"( 0ettin% the -al&e o an en-ironment -aria$le is done $. &sin% K#&ten-78"(

-x&lain fork#$ system call.


The K ork78" &sed to create a ne, #rocess rom an existin% #rocess( The ne, #rocess is called the child #rocess! and the existin% #rocess is called the #arent( @e can tell ,hich is ,hich $. checkin% the ret&rn -al&e rom K ork78"( The #arent %ets the child"s #id ret&rned to him! $&t 345

What are 'arious =s associated with a &rocess?


Unix identi ies each #rocess ,ith a &niG&e inte%er called 6rocessID( The #rocess that exec&tes the reG&est or creation o a #rocess is called the =#arent #rocess" ,hose 6ID is =6arent 6rocess ID"( E-er. #rocess is associated ,ith a #artic&lar &ser called the =o,ner" ,ho has #ri-ile%es o-er the #rocess( The identi ication or the &ser is 345

<rief about the initial &rocess se9uence while the system boots u&.
@hile $ootin%! s#ecial #rocess called the "s,a##er" or "sched&ler" is created ,ith 6rocess/ID A( The s,a##er mana%es memor. allocation or #rocesses and in l&ences CPU allocation( The s,a##er int&rn creates N children9 the #rocess dis#atcher!-hand and d$ l&sh ,ith IDs :!F and N res#ecti-el.( This is done $. exec&tin% the ile OetcOinit( 6rocess dis#atcher %i-es $irth to the shell( 345

What is a shell?

'1 A shell is an interactive user interface to an operating system ser-ices that allo,s an &ser to enter commands as character strin%s or thro&%h a graphical user interface( The shell con-erts them to s.stem calls to the O0 or orks o a #rocess to exec&te the command( 0.stem call res&lts and other in ormation rom the O0 345

How does the inode ma& to data block of a file?


Inode has :N $lock addresses( The irst :A are direct $lock addresses o the irst :A data $locks in the ile( The ::th address #oints to a one/le-el index $lock( The :Fth address #oints to a t,o/le-el 7do&$le in/direction8 index $lock( The :Nth address #oints to a three/le-el7tri#le in/direction8index $lock( This #ro-ides a -er. lar%e maxim&m 345

=iscuss the mount and unmount system calls


The #ri-ile%ed mo&nt s.stem call is &sed to attach a file system to a director. o another ile s.stemL the &nmo&nt s.stem call detaches a ile s.stem( @hen .o& mo&nt another ile s.stem on to .o&r director.! .o& are essentiall. s#licin% one director. tree onto a $ranch in another director. tree( The irst ar%&ment to 345

How do you create s&ecial files like named &i&es and de'ice files?
The s.stem call mknod creates s#ecial iles in the ollo,in% seG&ence( :( kernel assi%ns ne, inode! F( sets the file type to indicate that the ile is a #i#e! director. or s#ecial ile! N( I it is a de-ice ile! it makes the other entries like ma'or! minor de-ice n&m$ers( <or exam#le9 I the de-ice is a disk! ma'or 345

What is a * *@?
<I<O are other,ise called as =named #i#es"( <I<O 7 irst/in/ irst/ o&t8 is a s#ecial ile ,hich is said to $e data transient( Once data is read rom named #i#e! it cannot $e read a%ain( Also! data can $e read onl. in the order ,ritten( It is &sed in inter#rocess comm&nication ,here a #rocess ,rites to one end o 345

'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 &sed to assi%n more than one name to a ile! $&t cannot $e &sed to assi%n a director. more than one name or link ilenames on di erent computers( 0.m$olic link =is" a ile that onl. contains the name o another ile(O#eration 345

What are the Unix system calls for ?@?


o#en7#athname! la%!mode8 / open file creat7#athname!mode8 / create ile close7 iledes8 / close an o#en ile read7 iledes!$& er!$.tes8 / read data rom an o#en ile ,rite7 iledes!$& er!$.tes8 / ,rite data to an o#en ile lseek7 iledes!o set! rom8 / #osition an o#en ile d&#7 iledes8 / d&#licate an existin% ile descri#tor d&#F7old d!ne, d8 / d&#licate to a desired ile descri#tor cntl7 iledes!cmd!ar%8 / chan%e #ro#erties o an o#en ile ioctl7 iledes!reG&est!ar%8 / chan%e the $eha-io&r 345

<rief about the directory re&resentation in UN !


s a ile containin% a corres#ondence $et,een ilenames and inodes( A director. is a s#ecial ile that the kernel maintains( Onl. kernel modi ies directories! $&t #rocesses can read directories( The contents o a director. are a list o ilename and inode n&m$er #airs( @hen ne, directories are created! kernel makes t,o entries 345

What is /inode0?
All UNIX iles ha-e its descri#tion stored in a str&ct&re called =inode"( The inode contains in o a$o&t the ile/siBe! its location! time o last access! time o last modi ication! #ermission and so on( Directories are also re#resented as iles and ha-e an associated inode( In addition to descri#tions a$o&t the ile! the inode contains #ointers 345

)7

How are de'ices re&resented in UN !?


All de-ices are re#resented $. iles called s#ecial iles that are located inOde- director.( Th&s! de-ice iles and other iles are named and accessed in the same ,a.( A =re%&lar ile" is '&st an ordinar. data ile in the disk( A =$lock s#ecial ile" re#resents a de-ice ,ith characteristics similar to a disk 7data trans er 345

<rief about the directory re&resentation in UN !


A Unix director. is a ile containin% a corres#ondence $et,een ilenames and inodes( A director. is a s#ecial ile that the kernel maintains( Onl. kernel modi ies directories! $&t #rocesses can read directories( The contents o a director. are a list o ilename and inode n&m$er #airs( @hen ne, directories are created! kernel makes t,o entries 345

What is /inode0?
All UNIX iles ha-e its descri#tion stored in a str&ct&re called =inode"( The inode contains in o a$o&t the ile/siBe! its location! time o last access! time o last modi ication! #ermission and so on( Directories are also re#resented as iles and ha-e an associated inode( In addition to descri#tions a$o&t the ile! the inode contains #ointers 345

How are de'ices re&resented in UN !?


All de-ices are re#resented $. iles called s#ecial iles that are located inOde- director.( Th&s! de-ice iles and other iles are named and accessed in the same ,a.( A =re%&lar ile" is '&st an ordinar. data ile in the disk( A =$lock s#ecial ile" re#resents a de-ice ,ith characteristics similar to a disk 7data trans er 345
How is the command $cat file2 different from $cat >file2 Answer The Commond $cat file in unix is used to display the content of the file and where as commond $cat >> file is to append the text to the end of the file without overwritting the information of the file. Incase if the file does not exist in the directory the commond will create a newfile in file system.

)1

$cat >file means to create a new file $cat file means to open an existing file.
Answered By: selva,ravi Date: 7/1 /!""7

cat > file it means creating file for file cat file it means used to display the file content

xplain the steps that a shell follows while processing a command. !hen processing a command the searchs for the utility for the command in the directories specified in the "#TH vari$le and it in invo%es that utility. That utility will execute the command with help of %ernel and the output is given to shell. #nd then the displays out put to the user.

Answer

xplain the steps that a shell follows while processing a command. !hen processing a command the searchs for the utility for the command in the directories specified in the "#TH vari$le and it in invo%es that utility. That utility will execute the command with help of %ernel and the output is given to shell. #nd then the displays out put to the user.

Answer

!hich command is used to delete all files in the current directory and all its su$& directories'

(rm &fr )*irectory name> ( rm &rf + Answer


Answered By: A#it S$i%nis Date: 1!/!&/!""7

rm &r +

)2

!hat is the use of the command ,ls &x chapter-.&/0,

Answer

1es you are correct. It stands for listing the files Chapter with suffix . to / $ut it will display the files in columns as with&x option.

How does the %ernel differentiate device files and ordinary files'

*evice filles are of 2 types &&& charcater device file and $loc% device file type field in the file2s inode structure Answer $&&& $loc% device file c&&& character device file

How to switch to a super user status to gain privileges'

Answer

3se 4su5 command. The system as%s for password and when valid entry is made the user gains super user 6admin7 privileges.

!hat are shell varia$les'

Answer

8hell varia$les are system environment varia$les.They include T 9:;8H <<; :#I< the output of the shell varia$le we can see $y typing the command

)3

$>echo $T 9: ansi at the prompt.

!hat is redirection'

9edirection is a feature in 3nix where the data from the standard out put or a file;so on.can $e redirected i.e divert to a file or a program and vice versa. Answer > && out put redirection >> && out put redirectin6appending at the last7 ) && input redirection

How to terminate a process which is running and the specialty on command %ill ='

Answer

!ith the help of %ill command we can terminate the process. 8yntax> %ill pid ?ill = & %ills all processes in your system except the login shell.

How to terminate a process which is running and the specialty on command %ill ='

Answer

!ith the help of %ill command we can terminate the process. 8yntax> %ill pid ?ill = & %ills all processes in your system except the login shell.

How to sfind free space in unix@linux

)'

Answer

*f and du commands are used for chec%ing free space on dis% . df &h or df &Humanreada$le gives human reada$le format of free space.

!hat is the difference $etween soft lin% and hard lin% in unix operating system '

Hard <in%s > .. #ll <in%s have same inode num$er. 2.ls &l command shows all the lin%s with the lin% column68econd7 shows Ao. of lin%s. B. <in%s have actual file contents C.9emoving any lin% ;Dust reduces the lin% count ; $ut doesn2t affect other lin%s. Answer 8oft <in%s68ym$olic <in%s7 > ..<in%s have different inode num$ers. 2. ls &l command shows all lin%s with second column value . and the lin% points to original file. B. <in% has the path for original file and not the contents. C.9emoving soft lin% doesn2t affect anything $ut removing original file ;the lin% $ecomes ,dangling, lin% which points to nonexistant file.

to concatenate 6attach7 two strings'

Eor concatenating two string we use cat command. Answer x>& cat str. str2

xplain the 3AIF ?ernel.

))

Answer

3AIF ?ernel is heart of the operating system. 3AIF %ernal is loaded first when 3AIF system is $ooted. It handles allocation of devices; cpu; memory from that ponint on.

How many prompts are availa$le in a 3AIF system'

3nix@ <inux 8upports four "rompts "8.; "82; "8B; "8C Answer (;G;$;H are C prompts

47I747NC7S: Boo-s:
1!&ntroduction to U9&: N S?8LL programming, ,.>. Men-atesh ,urth$, 4earson 8ducation. 2!Uni% concepts and applications, 2ourth 8dition, Sumitabha Das, 3,?.

)+
3!Uni% for programmers and users, 3rd edition, >aham >lass N F. <bles, pearson education. '!Uni% and shell 4rogramming P< te%t boo-, B.<. 2orou0an N @.2. >iberg, 3homson. )!Beginning shell scripting, 8. 2oster P Dohnson N other, *ile Z# &ndia.

You might also like