SWL Writeups (RachanaS)

Embed Size (px)

Citation preview

  • 8/12/2019 SWL Writeups (RachanaS)

    1/76

    310254: SOFTWARE LABORATORY

    Teaching scheme: Examination scheme:

    !actica": 4 #!s$Wee%

    !actica": 50 ma!%s Te!m &o!%: 25 ma!%s

    List o' assignments

    1. Design suitable data structures and implement pass-I of a two-pass assemblerfor 8 bit microprocessor/ pseudo-machine. Implementation should consist of afew instructions from each category and few assembler directives.

    2. Implement pass-II of a two-pass assembler for 8-bit microprocessor/ pseudo-machine. The output of assignment-1 intermediate file and symbol table!should be input for this assignment.

    ". Design suitable data structures and implement pass-I of a two-pass macro-processor.

    #. $rite a program for pass-II of a two-pass macro-processor. The output ofassignment-" %&T' %DT and file without any macro definitions! should beinput for this assignment

    (OTE: Fo! A)o*e 4 assignments +se ,!o,e! ta)"e han-"ing techni.+es "i%e

    hashing

    (. $rite a program to create Dynamic )in* )ibrary for any mathematicaloperation and write an application program to test it.

    +. $rite a program to implement following scheduling algorithms

    ,irst ome ,irst erve'hortest ob ,irst 0reemptive!'0riority/ound-obin &on- 0reemptive!.

    . $rite a program to implement following scheduling algorithms31. )east ecently 4sed2. 5ptimal page replacement

    8. $rite a program to implement eader-writer problem using mute6/ semaphore

    7. $rite a program to implement an*er9s :lgorithm

  • 8/12/2019 SWL Writeups (RachanaS)

    2/76

    oftware )ab T.;.omputer

    1oin' e6ec family' wait. for processmanagement

    12. tudy of *ernel' types of *ernel' 4&I=/ )inu6 *ernel re-compilation.

    /nst!+ctions:

    tudents must submit the term-wor* in the form of >ournal. ;ach assignment has tobe well documented. taff in charge will assess the assignments continuously andgrade or mar* each assignment on completion date declared for each assignments.5perating systems assignments should be TIT)? conducted using 5pen-ource

    platform.Re'e!ence Boo%s:

    1. :dam @oover' Aystem 0rogramming with and 4&I=B' 0earson ;ducation

    2. ichard tevens3 :dvanced 0rogramming in the 4&I= environment' 0earson;ducation

    ". Aeginning )inu6 0rogrammingB' $ro6 0ress

    &ote3 The practical e6amination will be based on the assignments performed by thecandidates as part of the term-wor*. Cuestions will be as*ed during the practical

    e6amination to >udge the understanding of the students. It is e6pected that thestudent *now the theoretical aspect of the problem.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    3/76

    oftware )ab T.;.omputer

    STESs Smt ashi)ai (a*a"e o""ege o' Engg

    e,a!tment o' om,+te! Engg

    TEom,+te!

    List o' assignments

    S+)ect : So't&a!e La)

    1. $rite a program to implement pass-I of a two-pass assembler for 8 bitmicroprocessor

    2. $rite a program to implement pass-II of a two-pass assembler for 8-bit

    ". $rite a program to implement pass-I of a two-pass macro-processor.

    #. $rite a program for pass-II of a two-pass macro-processor.

    (. $rite a program to create Dynamic )in* )ibrary for arithmetic operation li*eaddition' subtraction' multiplication' division.

    +. $rite a program to implement following scheduling algorithmsa! ,irst ome ,irst erve'

    b! hortest ob ,irst 0reemptive!'c! 0riority/ound-obin &on-0reemptive!.

    . $rite a program to implement following scheduling algorithms3a! )east ecently 4sed

    b! 5ptimal page replacement

    8. $rite a program to implement eader-writer problem using mute6 / semaphore.

    7 $rite a program to implement an*er9s :lgorithm

    1< $rite a program to implement producer-consumer algorithm using multi-

    threading concept.

    11 tudy assignment on 4&I= system calls li*e ps' for*' >oin' e6ec family' wait' forprocess management.

    12. tudy assignment on *ernel' types of *ernel' 4&I=/ )inu6 *ernel re-compilation.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    4/76

    oftware )ab T.;.omputer

    Assignment (o : 1Tit"e:

    #6,othetica" Assem)"e! 7ass /8

    O)ecti*e :

    To +n-e!stan- Assem)"e! esign7ass /8

    !o)"em Statement:

    $rite a program to implement the 0ass I of two pass assembler for 8

  • 8/12/2019 SWL Writeups (RachanaS)

    5/76

    oftware )ab T.;.omputer

    2! siNe G siNe of memory area reEuired by D/D"! locFcntr G locFcntr K siNe#! Jenerate I OD)' code!P9

    f! If an imperative statement1! code G machine opcode from 50T:

    2! locFcntr G locFcntr K instruction len from 50T:"! If operand is literal then thisFliteral G literal in operand field )ITT:HlittabFptr G thisFliteral littabFptr G littabFptr K 1;lse i.e. 5perand is a symbol! thisFentry G ?%T: entry no of operand Jenerate I O I'code!'thisFentry!9

    ". 0rocessing of ;&D statement!a. 0erform step 2b!

    b. Jenerate I O:D'

  • 8/12/2019 SWL Writeups (RachanaS)

    6/76

    oftware )ab T.;.omputer

    Assignment (o : 2

    Tit"e:

    #6,othetica" Assem)"e! 7ass //8

    O)ecti*e :

    To +n-e!stan- Assem)"e! esign 7ass//8

    !o)"em Statement:

    $rite a program to implement the 0ass II of two pass assembler for 8 bit microprocessor'subset should contain few instructions from each category and few assembler directives.

    NOTE: For this assignments use proper table handling techniques like hashing.

    Theo!6:

    Databases reEuired for the design of the assembler31. 5pcode Table %nemonic' 5pcode' 5perand1'5perand2')ength of Instruction'lass of

    Instruction!2. ybol Table &ame of ymbol' :ddr of ymbol!". )iteral Table )iteral ' :ddr. 5f )iteral!#. 0ool Table Inde6 of )iter 0ool!(. Intermediate ode Table )ocation ounter ' 5pcode ' 5perand1'5perand2!+. 5b>ect ode Table )ocation ounter ' 5pcode ' 5perand1'5perand2 !

    A"go!ithm:

    Assem)"e! ,ass9 //:

    1. codeFareaFaddress G address of code areapooltabFptr G 1locFcntr G ect option and clic* on ,inish button. The $in"2 D)) filewill get created.

    Ste, 3:The wor*space for test will be created. &ow at the end of test.cpp write following code int Fstdcall sum int 6' int y! S

    return 6Ky U

    int Fstdcall diff int 6' int y! S

    return 6-y U int Fstdcall mul int 6' int y! S

    return 6Vy U int Fstdcall div int 6' int y! S

    return 6/y UThis test.cpp will serve as a entry point for the D)). The actual functions are defined in this file .

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    15/76

    oftware )ab T.;.omputer

    Ste, 4: &ow clic* on file &ew. Then clic* the Te6t file. Jive the filename as test.def. The test.defwill be created. Then write following code in it

    )I:? test

    ;=05T

    sum W1diff W2mul W"div W#

    Ste, 5:&owclic*on built option of the menu bar and clic* on build test.dll. the test.dll will getcreated. This dll file will be in test folder in debug folder. opy this test.dll to a directory$I&D5$.

    Ste, =:&ow close QKK and open visual basic. 5n a form place three te6t bo6es namely te6t1'te6t2' te6t". :nd place three command buttons for arithmetic operations. $rite following code invisual basic.

    0rivate Declare ,unction sum )ib Xtest.dllX yQal 6 :s )ong' yQal y :s )ong! :s )ong0rivate Declare ,unction diff )ib Xtest.dllX yQal 6 :s )ong' yQal y :s )ong! :s )ong0rivate Declare ,unction mul )ib Xtest.dllX yQal 6 :s )ong' yQal y :s )ong! :s )ong0rivate Declare ,unction div )ib Xtest.dllX yQal 6 :s )ong' yQal y :s )ong! :s )ong

    0rivate ub ommand1Flic*!

    Te6t".Te6t G trsumIntTe6t1.Te6t!' IntTe6t2.Te6t!!!;nd ub

    0rivate ub ommand2Flic*!Te6t".Te6t G trdiffIntTe6t1.Te6t!' IntTe6t2.Te6t!!!;nd ub

    0rivate ub ommand"Flic*!Te6t".Te6t G trmulIntTe6t1.Te6t!' IntTe6t2.Te6t!!!

    ;nd ub

    0rivate ub ommand#Flic*!Te6t".Te6t G trdivIntTe6t1.Te6t!' IntTe6t2.Te6t!!!;nd ub

    Ste, >:

    The output can be seen as follows3

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    16/76

    oftware )ab T.;.omputer

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    17/76

    oftware )ab T.;.omputer

    Assignment (o : =

    Tit"e: ?o) Sche-+"ing A"go!ithms

    O)ecti*e :

    To +n-e!stan- @ sche-+"ing a"go!ithm

    !o)"em Statement : $rite a program to implement ,ollowing cheduling algorithms1! ,irst ome ,irst erve - ,,2! ound obin"! 0riority cheduling#! hortest ob ,irst Y , preemptive!

    Theo!6:

    @ sche-+"e! :

    It selects process from processes in memory that are ready to e6ecute' and allocates the 04 toone of them

    oa"s 'o! Sche-+"ing

    %a*e sure your scheduling strategy is good enough with the following criteria3

    @ti"iation$E''icienc63 *eep the 04 busy 1

  • 8/12/2019 SWL Writeups (RachanaS)

    18/76

    oftware )ab T.;.omputer

    This is aNon-Premptive scheduling algorithm. ,I,5 strategy assigns priority to processesin the order in which they reEuest the processor. The process that reEuests the 04 first isallocated the 04 first. $hen a process comes in' add its 0 to the tail of ready Eueue. $henrunning process terminates' Eueue the process 0! at head of ready Eueue and run it.Exam,"e 1:

    0rocess urst TimeP1 2#P "P! "

    uppose that the processes arrive in the order3P1'P'P!The Jantt hart for the schedule is3

    $aiting time forP1 G

  • 8/12/2019 SWL Writeups (RachanaS)

    19/76

    oftware )ab T.;.omputer

    28 Ro+n- Ro)in 7RR8:

    ;ach process gets a small unit of 04 time time quantum!' usually 1

  • 8/12/2019 SWL Writeups (RachanaS)

    20/76

    oftware )ab T.;.omputer

    !o)"em3 ound robin assumes that all processes are eEually important each receives an eEualportion of the 04. This sometimes produces bad results. onsider three processes that start at thesame time and each reEuires three time slices to finish. 4sing ,I,5 how long does it ta*e theaverage >ob to complete what is the average response time![ @ow about using round robin[

    V 0rocess : finishes after " slices' +' and 7. The average is "K+K7!/" G + slices.

    V 0rocess : finishes after slices' 8' and 7' so the average is K8K7!/" G 8 slices.

    ound obin is fair' but uniformly enefficient.

    So"+tion3 Introduce priority based scheduling.

    38 !io!it6 Sche-+"ing:

    un highest-priority processes first' use round-robin among processes of eEual priority. e-insertprocess in run Eueue behind all processes of greater or eEual priority.

    :llows 04 to be given preferentially to important processes. cheduler ad>usts dispatcher priorities to achieve the desired overall priorities for the

    processes' e.g. one process gets 7

  • 8/12/2019 SWL Writeups (RachanaS)

    21/76

    oftware )ab T.;.omputer

    So"+tion3 :JI&J! This starvation can be compensated for if the priorities are internallycomputed. uppose one parameter in the priority assignment function is the amount of time theprocess has been waiting. The longer a process waits' the higher its priority becomes. This strategytends to eliminate the starvation problem.

    Exam,"e 1:

    0rocess urst Time 0roorityP1 2# < @igh!P " 1P! " 2 )ow!

    The Jantt hart for the schedule is3

    Exam,"e 2:

    0rocess urst Time 0roorityP1 2# < @igh!P " 1P! " 2 )ow!

    The Jantt hart for the schedule is3

    48 Sho!test9?o)9Fi!st 7S?F8 Sche-+"ing:

    %aintain the eady Eueue in order of increasing >ob lengths. $hen a >ob comes in' insert it in theready Eueue based on its length. $hen current process is done' pic* the one at the head of theEueue and run it.

    Exam,"e 1:

    &on-0reemptive ,3

    0rocess :rrival Time urst Time

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    22/76

    oftware )ab T.;.omputer

    P1 Exam,"e 2:

    !eem,ti*e S?F

    , scheduling chart3

    :verage waiting time G 7 K 1 K < K2!/# - "

    omments3 , is proven optimal only when all >obs are available simultaneously.

    !o)"em3 , minimiNes the average wait time because it services small processes before itservices large ones. $hile it minimiNes average wait time' it may penaliNe processes with highservice time reEuests. If the ready list is saturated' then processes with large service times tend tobe left in the ready list while small processes receive service. In e6treme case' where the systemhas little idle time' processes with large service times will never be served. This total starvation oflarge processes may be a serious liability of this algorithm.

    So"+tion3 %ulti-)evel ,eedbac* Cueues.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    23/76

    oftware )ab T.;.omputer

    Assignment (o : >

    Tit"e: age Re,"acement A"go!ithm

    O)ecti*e :

    To +n-e!stan- aging once,t

    !o)"em Statement:

    $rite a program to implement following scheduling algorithms31. )east ecently 4sed.2. 5ptimal page replacement.

    $hen a page fault occurs' the operating system has to choose a page to remove frommemory to ma*e room for the page that has to be brought in. If the page to be removed has beenmodified while in memory' it must be rewritten to the dis* to bring the dis* copy up to date. If'however' the page has not been changed e.g.' it contains program te6t!' the dis* copy is already up

    to date' so no rewrite is needed.The page to be read in >ust overwrites the page being evicted. $hile it would be possible to

    pic* a random page to evict at each page fault' system performance is much better if a page that isnot heavily used is chosen. If a heavily used page is removed' it will probably have to be broughtbac* in Euic*ly' resulting in e6tra overhead. %uch wor* has been done on the sub>ect of pagereplacement algorithms' both theoretical and e6perimental.

    Basic age Re,"acement:

    Ste, 1 :

    ,ind the location of the desired page on dis*

    Ste, 2 :

    ,ind a free frame3-If there is a free frame' use it-If there is no free frame' use a page replacement algorithm to select a *ictim frame

    Ste, 3 :

    ring the desired page into the newly! free frame update the pageand frame tables

    Ste, 4:

    estart the process

    age Re,"acement A"go!ithms :

    1! Fi!st9/n9Fi!st9O+t 7F/FO8 A"go!ithm

    The simplest page-replacement algorithm is a ,I,5 algorithm. The first-in' first-out ,I,5!page replacement algorithm is a low-overhead algorithm that reEuires little boo*-*eeping onthe part of the operating system. The idea is obvious from the name - the operating system

    &5;' Dept. 5f omp. ;ngg.

    http://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/Operating_system
  • 8/12/2019 SWL Writeups (RachanaS)

    24/76

    oftware )ab T.;.omputer

    *eeps trac* of all the pages in memory in a Eueue' with the most recent arrival at the bac*' andthe earliest arrival in front. $hen a page needs to be replaced' the page at the front of the Eueuethe oldest page! is selected

    28 O,tima" age !e,"acement:

    when a page needs to be swapped in' the operating systemswaps out the page whose ne6t usewill occur farthest in the future. ,or e6ample' a page that is not going to be used for the ne6t +seconds will be swapped out over a page that is going to be used within the ne6t

  • 8/12/2019 SWL Writeups (RachanaS)

    25/76

    oftware )ab T.;.omputer

    38 Least !ecent"6 +se-

    )4 wor*s on the idea that pages that have been most heavily used in the past fewinstructions are most li*ely to be used heavily in the ne6t few instructions too. o leastrecently used page is replaced.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    26/76

    oftware )ab T.;.omputer

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    27/76

    oftware )ab T.;.omputer

    Assignment (o :

    Tit"e: Rea-e! W!ite! !o)"em

    O)ecti*e:

    To +n-e!stan- conce,t o' conc+!!enc6 an- s6nch!oniation

    !o)"em statement:

    $rite a program to implement eader-writer problem using mute6 / semaphore.

    Theo!6:

    In computer science' the 'i!st an- secon- !ea-e!s9&!ite!s ,!o)"emsare e6amples of a commoncomputing problem in concurrency. The two problems deal with situations in which manythreadsmust access the same shared memoryat one time' some reading and some writing' with the natural

    constraint that no process may access the share for reading or writing while another process is inthe act of writing to it. In particular' it isallowed for two or more readers to access the share at thesame time.! : readers-writer loc*is a data structurethat solves one or more of the readers-writersproblems.

    : data set is shared among a number of concurrent processes.

    eaders Yonly read the data set they do notperform any updates

    $riters Ycan both read and write

    0roblem Yallow multiple readers to read at the same time. 5nly one single writer canaccess the shared data at the same time.

    A"o!ithm :

    1. emaphore m+texinitialiNed to 12. emaphore &!tinitialiNed to 13. Integer read co+ntinitialiNed to ust what its name implies -- a reEuest for the operating system to do something onbehalf of the user]s program. The system calls are functions used in the *ernel itself. To theprogrammer' the system call appears as a normal function call. @owever since a system calle6ecutes code in the *ernel' there must be a mechanism to change the mode of a process from user

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    37/76

    oftware )ab T.;.omputer

    mode to *ernel mode. The compiler uses a predefined library of functions the library! thathave the names of the system calls. The library functions typically invo*e an instruction thatchanges the process e6ecution mode to *ernel mode and causes the *ernel to start e6ecutingcode for system calls. The instruction that causes the mode change is often referred to as anXoperating system trapX which is a software generated interrupt. The library routines e6ecute inuser mode' but the system call interface is a special case of an interrupt handler. The library

    functions pass the *ernel a uniEue number per system call in a machine dependent way -- either asa parameter to the operating system trap' in a particular register' or on the stac* -- and the *ernelthus determines the specific system call the user is invo*ing. In handling the operating systemtrap' the *ernel loo*s up the system call number in a table to find the address of the appropriate*ernel routine that is the entry point for the system call and to find the number of parameters thesystem call e6pects. The *ernel calculates the user! address of the first parameter to the systemcall by adding or subtracting' depending on the direction of stac* growth! an offset to the userstac* pointer' corresponding to the number of the parameters to the system call.

    ,inally' it copies the user parameters to the Xu areaX and call the appropriate system callroutine. :fter e6ecuting the code for the system call' the *ernel determines whether there was anerror. If so' it ad>usts register locations in the saved user register conte6t' typically setting the

    XcarryX bit for the 0 processor status! register and copying the error number into register getgi- get real group ID kernel2sched.c

    4 s6ssigna" :&I signal handling kernel2signal.c

    4G gete+i- get effective user ID kernel2sched.c

    50 getegi- get effective group ID kernel2sched.c

    51 acct enable or disable process accounting kernel2acct.c

    52 +mo+nt2 unmount a file system,s2super.c

    54 ioct" control device,s2ioctl.c

    55 'cnt" file control,s2,cntl.c

    5= m,x unimplemented!

    5> set,gi- set process group ID kernel2s6s.c

    5 +"imit unimplemented!

    5G o"-+name obsolete uname system call arch2i!342kernel2s6s5i!34.c

    =0 +mas% set file creation mas* kernel2s6s.c

    =1 ch!oot change root directory,s2open.c

    =2 +stat get file system statistics,s2super.c

    =3 -+,2 duplicate a file descriptor,s2,cntl.c

    =4 get,,i- get parent process ID kernel2sched.c

    =5 get,g!, get the process group ID kernel2s6s.c

    == setsi- creates a session and sets the process group ID kernel2s6s.c

    => sigaction 05I= signal handling functions arch2i!342kernel2signal.c= sgetmas% :&I signal handling kernel2signal.c

    =G ssetmas% :&I signal handling kernel2signal.c

    >0 set!e+i- set real and effective user IDs kernel2s6s.c

    >1 set!egi- set real and effective group IDs kernel2s6s.c

    >2 sigs+s,en- install a signal mas* and suspend caller until signalarch2i!342kernel2signal.c

    >3 sig,en-ing e6amine signals that are bloc*ed and pending kernel2signal.c

    >4 sethostname set hostname kernel2s6s.c

    >5 set!"imit set ma6imum system resource con sumption kernel2s6s.c

    >= get!"imit get ma6imum system resource con sumption kernel2s6s.c

    >> get!+sage get ma6imum system resource con sumption kernel2s6s.c> gettimeo'-a6 get the date and time kernel2time.c

    >G settimeo'-a6 set the date and time kernel2time.c

    0 getg!o+,s get list of supplementary group IDs kernel2s6s.c

    1 setg!o+,s set list of supplementary group IDs kernel2s6s.c

    2 o"-se"ect sync. I/5 multiple6ing arch2i!342kernel2s6s5i!34.c

    3 s6m"in% ma*e a symbolic lin* to a file,s2namei.c

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    42/76

    oftware )ab T.;.omputer

    4 "stat get file status,s2stat.c

    5 !ea-"in% read the contents of a symbolic lin*,s2stat.c

    = +se"i) select shared library,s2e'ec.c

    > s&a,on start swapping to file/device mm2sap,ile.c

    !e)oot reboot or enable/disable trl-:lt -Del kernel2s6s.c

    G o"-!ea--i! read directory entry,s2readdir.c

    G0 o"-mma, map pages of memory arch2i!342kernel2s6s5i!34.cG1 m+nma, unmap pages of memory mm2mmap.c

    G2 t!+ncate set a file to a specified length,s2open.c

    G3 't!+ncate set a file to a specified length,s2open.c

    G4 'chmo- change access permission mode of file,s2open.c

    G5 'cho&n change owner and group of a file,s2open.c

    G= get,!io!it6 get program scheduling priority kernel2s6s.c

    G> set,!io!it6 set program scheduling priority kernel2s6s.c

    G ,!o'i" e6ecut ion time profile

    GG stat's get file system statistics,s2open.c

    100 'stat's get file system statistics,s2open.c101 io,e!m set port input/output permissions arch2i!342kernel2ioport.c

    102 soc%etca"" soc*et system calls net2so cket.c

    103 s6s"og read and/or clear *ernel message ring buffer kernel2printk.c

    104 setitime! set value of interval timer kernel2itimer.c

    105 getitime! get value of interval timer kernel2itimer.c

    10= s6sne&stat get file status,s2stat.c

    10> s6sne&"stat get file status,s2stat.c

    10 s6sne&'stat get file status,s2stat.c

    10G o"-+name get name and information about current *ernelarch2i!342kernel2s6s5i!34.c

    110 io," change I/5 privilege level arch2i!342kernel2ioport.c111 *hang+, virtually hangup the current tty,s2open.c

    112 i-"e ma*e process < idle arch2i!342kernel2process.c

    113 *m=o"- enter virtual 8

  • 8/12/2019 SWL Writeups (RachanaS)

    43/76

    oftware )ab T.;.omputer

    12= sig,!ocmas% 05I= signal handling functions kernel2signal.c

    12> c!eatemo-+"e create a loadable module entry kernel2module.c

    12 initmo-+"e initialiNe a loadable module entry kernel2module.c

    12G -e"etemo-+"e delete a loadable module entry kernel2module.c

    130 get%e!ne"s6ms retrieve e6ported *ernel and module symbols kernel2module.c

    131 .+otact" manipulate dis* Euotas,s2dquot.c

    132 get,gi- get process group ID kernel2s6s.c133 'ch-i! change wor*ing directory,s2open.c

    134 )-'"+sh start' flush' or tune buffer-dirty-flush daemon,s2bu,,er.c

    135 s6s's get file system type information,s2super.c

    13= ,e!sona"it6 set the process e6ecution domain kernel2e'ec5domain.c

    13> a'ss6sca"" unimplemented!

    13 set's+i- set user identity used for file system chec*s kernel2s6s.c

    13G set'sgi- set group identity used for file system chec*s kernel2s6s.c

    140 s6s""see% move e6tended read/write file pointer,s2read5rite.c

    141 get-ents read directory entries,s2readdir.c

    142 se"ect sync. I/5 multiple6ing,s2select.c143 '"oc% apply or remove an advisory loc* on an open file,s2locks.c

    144 ms6nc synchroniNe a file with a memory map mm2,ilemap.c

    145 !ea-* read data into multiple buffers,s2read5rite.c

    14= &!ite* write data into multiple buffers,s2read5rite.c

    14> s6sgetsi- get process group ID of session leader kernel2s6s.c

    14 '-atas6nc synchroniNe a file]s in-core data with that on dis*,s2bu,,er.c

    14G s6sct" r ead/write system parameters kernel2s6sctl.c

    150 m"oc% loc* pages in memory mm2mlock.c

    151 m+n"oc% unloc* pages in memory mm2mlock.c

    152 m"oc%a"" disable paging for calling process mm2mlock.c

    153 m+n"oc%a"" reenable paging for calling process mm2mlock.c154 sche-set,a!am set scheduling parameters kernel2sched.c

    155 sche-get,a!am get scheduling parameters kernel2sched.c

    15= sche-setsche-+"e! set scheduling algorithm parameters kernel2sched.c

    15> sche-getsche-+"e! get scheduling algorithm parameters kernel2sched.c

    15 sche-6ie"- yield the processor kernel2sched.c

    15G sche-get,!io!it6max get ma6 static priority range kernel2sched.c

    1=0 sche-get,!io!it6min get min static priority range kernel2sched.c

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    44/76

    oftware )ab T.;.omputer

    Assignment (o : 12

    Tit"e:

    To st+-6 @nix$Lin+x e!ne"

    O)ecti*e:

    To o""ect /n'o!mation a)o+t Lin+x e!ne"

    Theo!6:

    The 4&I= *ernel is the central core of the operating system. It provides an interface to thehardware devices as well as to process' memory' and I/5 management. The *ernel managesreEuests from users via system calls that switch the process from user space to *ernel space see,igure 1.1!.;ach time a user process ma*es a system call such as read!' for*!' e6ec!' open!' and so on' theuser process e6periences a conte't sitch. : conte6t switch is a mechanism by which a processswitches from one state to another. The process may be either suspended until the system call iscompleted blocking!' or the process may continue and later be notified of the system call

    completion via a signal nonblocking!. ,igure 1.2 shows an e6ample of a conte6t switch. ,igure1.2 demonstrates a user process issuing a system call' in this case the read!1 system call. Theread! system call ta*es a file descriptor' buffer' and the number of bytes to be read as arguments.The read! system call forces the user process to bloc* until the completion or timeout of the read!

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    45/76

    oftware )ab T.;.omputer

    system call. %ost 4&I= operating system vendors provide a library for performing nonbloc*ingas6nchronous! I/5 calls since the traditional 4&I= I/5 calls of read!and write! are bloc*ings6nchronous!. The 4&I= *ernel provides services to different system resources including I/5'memory management' process management' and networ* services. : particular application or userprocess accesses the system resources and services via system calls. The performance of theapplication is highly dependent on the type of system calls used and the number of system calls per

    application. ernel resources are e6pensive and should be regarded as a valuable and limited set ofresources. In order to ma6imiNe performance' the application should minimiNe the amount ofsystem calls used' thereby reducing *ernel space overhead and maintaining the user process in userspace for most of the time. @owever' certain applications' such as a database management systemheavily dependent on I/5' cannot avoid system calls. The goal in this situation is to tune the 4&I=*ernel and the system to respond as Euic*ly and efficiently as possible so that the *ernel resourcescan be freed Euic*ly to service other reEuests. In other words' the goal of the application should beto minimiNe the amount of time spent in *ernel space while ma6imiNing throughput in the userspace.

    5ne of the ma>or system calls central to the 4&I= operating system is the for*! system call. Thefor*! system call creates another process *nown as the childprocess' while the process that issuedthe for*! system call becomes the parent process. The for*! system call duplicates the entireprocess structure and the process address space of the parent process. The child process inherits the>ob class characteristics and environment of the parent process. The child process also inheritsopen file descriptors from the parent process. ?ou can reference the parent process ID of a processusing the ps -ef command. The for*! system call enables one process to create another process

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    46/76

    oftware )ab T.;.omputer

    either synchronously by waiting on the child process' or asynchronously by continuing thee6ecution of the parent process. The for*! system call ta*es no arguments and returns an integer.The return value can represent one of three distinct values.1.

  • 8/12/2019 SWL Writeups (RachanaS)

    47/76

    oftware )ab T.;.omputer

    The 4&I= operating system consists of many different layers that manage different resources andservices. The basic architecture of the 4&I= operating system 5! consists of two main layers3the system or *ernel layer' and the user layer. ,igure 1.# illustrates the different layers of the4&I= operating system. 12 @(/I AR#/TET@RE

    ER(EL LAYER :

    The *ernel layer is the core of the operating system and provides services such as processand memory management' I/5 services' device drivers' >ob scheduling' and low-level hardwareinterface routines such as test and set instructions. The *ernel layer consists of many differentinternal routines that process the user reEuests. :ccess to the *ernel is indirect via system calls.?ou cannot call the internal *ernel routines directly. The system calls provide a mechanism bywhich a user process via the system call can reEuest a *ernel resource or service. The *ernel itselfis relatively small in terms of its dis* and memory storage siNes.

    5n eEuent systems' the *ernel is located in the root directory and consists of a single filenamed uni6 /uni6!. The siNe of the 4&I= *ernel on eEuent systems varies depending on thesystem configuration and the number of device drivers configured. : typical siNe may range from

    1 %Y( %. 5n olaris systems' the file path for the 4&I= *ernel is/platform/LplatformFtypeM/*ernel/uni6. The LplatformFtypeM indicates the type of systemarchitecture such as sun#m or sun#u. It is important to note that when the operating system isinstalled on the machine' you must allocate enough space for the root file system. If you do notallocate sufficient space' you may not be able to rebuild the *ernel because rebuilding the *ernelreEuires a temporary staging area to hold both the new *ernel and the previous *ernel file. Inaddition' you may also not be able to install operating system patches if sufficient free space doesnot e6ist in the root file system. I recommend that you always leave at least (

  • 8/12/2019 SWL Writeups (RachanaS)

    48/76

    oftware )ab T.;.omputer

    root file system. :lthough this may seem high' rebuilding the root file system to increase its spaceis not an easy tas*. It is better to have e6tra space than be short a few megabytes.

    The *ernel also provides services such as signal handling' synchroniNation' interprocesscommunication' file system services' networ* services' and hardware monitoring. ;ach time aprocess is started' the *ernel has to initialiNe the process' assign the process a priority' allocatememory and resources for the process' and schedule the process to run. $hen the process

    terminates' the *ernel frees any memory and/or resources held by the process.

    in-s o' e!ne"s

    There are four popular categories or *inds of ernels namely monolithic *ernels' micro*ernels'hybrid *ernels and e6o*ernels.

    ono"ithic %e!ne"sare part of 4ni6-li*e operating systems li*e )inu6 ',reeD etc. These typesof *ernels consist of the core functions of the operating system and the device drivers with theability to load modules at runtime.

    ic!o %e!ne"s are part of the operating systems li*e :I=' e5' @urd' %ach' %ac 5 ='%I&I=' C&=. ;tc. These types of *ernels normally provide only the minimal services such asdefining memory address spaces' Inter-process communication I0! and the process management.The other functions such as running the hardware processes are not handled directly bymicro*ernels.

    #6)!i- %e!ne"sare part of the operating systems such as %icrosoft $indows &T' 2

  • 8/12/2019 SWL Writeups (RachanaS)

    49/76

    oftware )ab T.;.omputer

    To !e-+ce the sie o' the %e!ne":

    uppose you are a )inu6 fanatic and you need an 5 in your mobile. The typical 5 you get hasthe all the miscellaneous components and has siNe in many % s' which you can9t afford in yourmobile. Do a *ernel recompilation' and remove unwanted modules.

    $hen the siNe of the *ernel is reduced removing the unwanted items' less memory will be usedwhich in turn will increase the resource available to applications.

    To a-- o! !emo*e s+,,o!t 'o! -e*ices:

    ,or each device' a device driver is needed for communicating with the operating system. ,ore6ample' if a 4 device is attached to a computer' we need to enable the corresponding devicedriver for it to wor*. In technical terms' the support for 4 driver is to be enabled in the *ernel.

    To mo-i'6 s6stem ,a!amete!s:

    ystem parameters include high memory support' Euota support etc. ,or managing physicalmemory above # J' high memory support +# J! needs to be enabled.

    #o& -o &e !ecom,i"e a %e!ne"M

    1. Qerify and update the pac*ages reEuired2. 5btain *ernel source". 5btain current hardware details#. onfigure *ernel(. uild *ernel+. onfigure the oot loader

    . eboot the server

    1 ;e!i'6 an- +,-ate the ,ac%ages !e.+i!e-

    ?ou need to do this step only if you upgrade the *ernel from version 2.# to 2.+. ?ou can s*ip thisstep if it is a 2.+.6 to 2.+.6 upgrade.

    efore upgrading the *ernel' you need to ma*e sure that your system is capable of accepting thenew *ernel. hec* the utilities that interact with your system' and verify that they are up-to-date. Ifthey are not' go ahead and upgrade them first.

    The main pac*ages to be chec*ed and upgraded are 3 binutils' e2fsprogs' procps' gcc and module-init-tools

    ?ou should ta*e e6treme care while upgrading mo-+"e9init9too"s. : module is a piece of code thatcan be inserted into the *ernel on demand. %odule-init-tools provide utilities for managing )inu6*ernel modules - for loading' unloading'listing and removing modules.

    The main utilities available are 3

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    50/76

    oftware )ab T.;.omputer

    insmod rmmod modprobe depmod lsmod

    oth modprobe and insmod are used to insert modules. The only difference is that insmod doesn9t*now the location of the module and is unaware of dependencies. %odprobe does this by parsingthe file2lib2modules27kernel version82modules.dep

    #o& to insta"" mo-+"e9init9too"s

    Jet the source http3//www.*ernel.org/pub/linu6/utils/*ernel/module-init-tools/module-init-tools-".2.2.tar.gN to the server using wget and untar it.

    tar -N6f module-init-tools-".2.2.tar.gN

    2. onfigure it.

    cd module-init-tools-".2.2./configure --prefi6G/

    ". ename the e6isting 2.# version of this utility as utility.old

    ma*e moveold

    #. uild and install.

    ma*ema*e install

    (. un the script generate-modprobe.conf to convert the entries in the module configuration file for*ernel version 2.# /etc/modules.conf ! to a file used by *ernel version 2.+ /etc/modprobe.conf!

    ./generate-modprobe.conf /etc/modprobe.conf

    +. hec* the version of current module-init-tools

    depmod -Q

    2 O)tain the e!ne" So+!ce

    Jet the *ernel source fromhttp3//www.*ernel.org/pub/linu6/*ernel/v2.+/

    ?ou can download the source to the2usr2src2kernelsfolder in your server. If you are planning torecompile your *ernel to version 2.+.17.2' the steps would be 3

    &5;' Dept. 5f omp. ;ngg.

    http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.2.tar.gzhttp://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.2.tar.gzhttp://www.kernel.org/pub/linux/kernel/v2.6/http://www.kernel.org/pub/linux/kernel/v2.6/http://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.2.tar.gzhttp://www.kernel.org/pub/linux/utils/kernel/module-init-tools/module-init-tools-3.2.2.tar.gzhttp://www.kernel.org/pub/linux/kernel/v2.6/
  • 8/12/2019 SWL Writeups (RachanaS)

    51/76

    oftware )ab T.;.omputer

    HrootRcd /usr/src/*ernelsHrootRwget http3//www.*ernel.org/pub/linu6/*ernel/v2.+/linu6-2.+.17.2.tar.gNHrootRtar N6f linu6-2.+.17.2.tar.gNHrootRcd linu6-2.+.17.2

    3 O)tain the +!!ent #a!-&a!e etai"s

    The current @ardware details can be obtained using the following commands3

    "s,ci

    This utility gives the details about the networ* card and all devices attached to the machine. If youtype "s,ciand get an error Alscpi3 command not foundB' you will have to installpciutils-.1.99.test3-!.$ rpmin the server.

    : typical "s,cioutput will be as follows 3

    HrootW===== `R lspci

  • 8/12/2019 SWL Writeups (RachanaS)

    52/76

    oftware )ab T.;.omputer

    HrootW==== `R cat /proc/cpuinfoprocessor 3 L&umberM bNImage

    ma*e ->L&umberM modulesma*e ->L&umberM modules-Install

    -> tells your system to do that many >obs in %a*efile together which will in turn reduce the time forcompilation.

    L&umberM is two times the number of cpus in your system or number of virtual processors. Thisnumber can be found using the command

    cat /proc/cpuinfo grep processor wc -lHrootW====R cat /proc/cpuinfo grep processor wc -l

    2

    5nce this is done copy all these to the2bootfolder as follows 3

    cp .config /boot/config-2.+.17.2cp arch/i"8+/boot/bNImage /boot/vmlinuN-2.+.17.2cp ystem.map /boot/ystem.map-2.+.17.2m*initrd /boot/initrd-2.+.7.img 2.+.17.2

    m%init!-is the program to create initial :% Dis* Image.

    = on'ig+!e Boot Loa-e!

    oot loader is the first program that runs when a computer boots. There are two types of bootloader 3

    J4 )I)5

    1 ete!mine the c+!!ent"6 insta""e- )oot "oa-e! :

    hec* first (12 bytes of the boot drive. hec* for grub first3

    R dd ifG/dev/hda bsG(12 countG1 2M\1 grep J4

    If it matches' the current boot loader is grub. hec* for lilo if it did not match3

    R dd ifG/dev/hda bsG(12 countG1 2M\1 grep )I)5

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    59/76

    oftware )ab T.;.omputer

    (ote3 If the hard dis* is I or :T:' use sda instead of hda..

    2 on'ig+!e the )oot "oa-e!

    If your boot loader is )I)5' add entries for the new *ernel in the file2etc2lilo.con,. : typical liloentry will be as given below 3

    imageG/boot/vmlinuN-2.+.17.2labelGlinu6initrdG/boot/initrd-2.+.17.2.imgread-onlyappendGXconsoleGtty< consoleGtty1'172

    Do &ot change the AdefaultB value in the file grub.conf. ;nter grub command prompt by typing thecommand g!+)at the prompt. ;nter the below command at the grub prompt3

    savedefault --defaultG" --once

    This is the case if the newly added entry is having inde6 ". ;6it from grub-shell.

    >Re)oot the Se!*e!

    eboot the server using the command !e)oot. If by any chance' a *ernel panic occurs' server will

    be up with the old wor*ing *ernel. If everything goes fine' the server will be up with the new*ernel. 5nce it is up with the new *ernel' do not forget to change the default value in the bootloader.

    onc"+sion

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    60/76

    oftware )ab T.;.omputer

    ooting a newly recompiled *ernel in your first attempt is a tough tas* and is at times thoughtimpossible. ,ollowing the above steps and *eeping the compilation tric*s in mind' there is nodoubt ernel ompilation will now be a piece of ca*e.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    61/76

    oftware )ab T.;.omputer

    ORAL D+estion Ban%

    18 #o& can 6o+ te"" &hat she"" 6o+ a!e !+nning on a @(/I s6stemM

    ?ou can do the ;cho :&D5%. It will return a undefined variable if you are from the -hell' >ust a return prompt if you are from the ourne shell' and a ( digit random numbersif you are from the orn shell. ?ou could also do a ps -l and loo* for the shell with the

    highest 0ID.

    28 What a!e con-itions on &hich -ea-"oc% can occ+! &hi"e s&a,,ing the ,!ocessesM

    :ll processes in the main memory are asleep. :ll Oready-to-run9 processes are swapped out.There is no space in the swap device for the new incoming process that are swapped out ofthe main memory. There is no space in the main memory for the new incoming process.

    38 #o& -o 6o+ change Fi"e Access e!missionsM

    :nswer 3;very file has following attributes3owner9s user ID 1+ bit integer !owner9s group ID 1+ bit integer !

    ,ile access mode wordOr w 6 -r w 6- r w 69user permission-group permission-others permission!r-read' w-write' 6-e6ecuteTo change the access mode' we use chmodfilename'mode!.;6ample3To change mode of myfile to Orw-rw-rY9 ie. read' write permission for user - read'writepermission for group - only read permission for others! we give the args as3chmodmyfile'

  • 8/12/2019 SWL Writeups (RachanaS)

    62/76

    oftware )ab T.;.omputer

    58 What is the -i''e!ence )et&een S&a,,ing an- agingM

    wapping3$hole process is moved from the swap device to the main memory for e6ecution. 0rocesssiNe must be less than or eEual to the available main memory. It is easier to implementationand overhead to the system. wapping systems does not handle the memory more fle6iblyas compared to the paging systems.

    0aging35nly the reEuired memory pages are moved to main memory from the swap device fore6ecution. 0rocess siNe does not matter. Jives the concept of the virtual memory.

    It provides greater fle6ibility in mapping the virtual address space into the physicalmemory of the machine. :llows more number of processes to fit in the main memorysimultaneously. :llows the greater process siNe than the available physical memory.Demand paging systems handle the memory more fle6ibly.

    =8 What is the -i''e!ence )et&een cm, an- -i'' comman-sM

    cmp - ompares two files byte by byte and displays the first mismatchdiff - tells the changes to be made to ma*e the files identical

    >8 What is meant )6 the nice *a"+eM

    &ice value is the value that controls Sincrements or decrementsU the priority of the process.This value that is returned by the nice ! system call. The eEuation for using nice value is30riority G Arecent 04 usageB/constant! K base- priority! K nice value!5nly the administrator can supply the nice value. The nice ! system call wor*s for therunning process only. &ice value of one process cannot affect the nice value of the otherprocess.

    8 What is a -aemonM: daemon is a process that detaches itself from the terminal and runs' disconnected' in thebac*ground' waiting for reEuests and responding to them. It can also be defined as thebac*ground process that does not belong to a terminal session. %any system functions arecommonly performed by daemons' including the sendmail daemon' which handles mail'and the &&T0 daemon' which handles 4;&;T news. %any other daemons may e6ist.ome of the most common daemons are3init3 Ta*es over the basic running of the system when the *ernel has finished the bootprocess.inetd3 esponsible for starting networ* services that do not have their own stand-alonedaemons. ,or e6ample' inetd usually ta*es care of incoming rlogin' telnet' and ftp

    connections.cron3 esponsible for running repetitive tas*s on a regular schedule.

    G8 What a!e the ,!ocess states in @(/IM

    :s a process e6ecutes it changes state according to its circumstances. 4ni6 processes havethe following states3unning 3 The process is either running or it is ready to run .$aiting 3 The process is waiting for an event or for a resource.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    63/76

    oftware )ab T.;.omputer

    topped 3 The process has been stopped' usually by receiving a signal.ombie 3 The process is dead but have not been removed from the process table.

    108 #o& a!e -e*ices !e,!esente- in @(/IM

    :ll devices are represented by files called special files that are located in/dev directory.Thus' device files and other files are named and accessed in the same way. : ]regular file]is >ust an ordinary data file in the dis*. : ]bloc* special file] represents a device with

    characteristics similar to a dis* data transfer in terms of bloc*s!. : ]character special file]represents a device with characteristics similar to a *eyboard data transfer is by stream ofbits in seEuential order!.

    118 What is Hino-eHM

    :ll 4&I= files have its description stored in a structure called ]inode]. The inode containsinfo about the file-siNe' its location' time of last access' time of last modification'permission and so on. Directories are also represented as files and have an associatedinode. In addition to descriptions about the file' the inode contains pointers to the databloc*s of the file. If the file is large' inode has indirect pointer to a bloc* of pointers toadditional data bloc*s this further aggregates for larger files!. : bloc* is typically 8*.

    Inode consists of the following fields3 ,ile owner identifier ,ile type ,ile access permissions ,ile access times &umber of lin*s ,ile siNe )ocation of the file data

    128 B!ie' a)o+t the -i!ecto!6 !e,!esentation in @(/I

    : 4ni6 directory is a file containing a correspondence between filenames and inodes. :

    directory is a special file that the *ernel maintains. 5nly *ernel modifies directories' butprocesses can read directories. The contents of a directory are a list of filename and inodenumber pairs. $hen new directories are created' *ernel ma*es two entries named ].] refersto the directory itself! and ]..] refers to parent directory!.ystem call for creating directory is m*dir pathname' mode!.

    138 What a!e the @nix s6stem ca""s 'o! /$OM

    openpathname'flag'mode! - open file creatpathname'mode! - create file closefiledes! - close an open file readfiledes'buffer'bytes! - read data from an open file

    writefiledes'buffer'bytes! - write data to an open file lsee*filedes'offset'from! - position an open file dupfiledes! - duplicate an e6isting file descriptor dup2oldfd'newfd! - duplicate to a desired file descriptor fcntlfiledes'cmd'arg! - change properties of an open file ioctlfiledes'reEuest'arg! - change the behaviour of an open fileThe difference between fcntl anf ioctl is that the former is intended for any open file' while

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    64/76

    oftware )ab T.;.omputer

    the latter is for device-specific operations.

    148 #o& -o 6o+ change Fi"e Access e!missionsM

    ;very file has following attributes3 owner]s user ID 1+ bit integer ! owner]s group ID 1+ bit integer !

    ,ile access mode word]r w 6 -r w 6- r w 6]user permission-group permission-others permission!r-read' w-write' 6-e6ecuteTo change the access mode' we use chmodfilename'mode!.;6ample 13To change mode of myfile to ]rw-rw-r--] ie. read' write permission for user - read'writepermission for group - only read permission for others! we give the args as3chmodmyfile'

  • 8/12/2019 SWL Writeups (RachanaS)

    65/76

    oftware )ab T.;.omputer

    ,or e6ample3If the device is a dis*' ma>or device number refers to the dis* controller and minor devicenumber is the dis*.

    18 isc+ss the mo+nt an- +nmo+nt s6stem ca""s

    The privileged mount system call is used to attach a file system to a directory of another

    file system the unmount system call detaches a file system. $hen you mount another filesystem on to your directory' you are essentially splicing one directory tree onto a branch inanother directory tree. The first argument to mount call is the mount point' that is ' adirectory in the current file naming system. The second argument is the file system tomount to that point. $hen you insert a cdrom to your uni6 system]s drive' the file system inthe cdrom automatically mounts to /dev/cdrom in your system.

    1G8 #o& -oes the ino-e ma, to -ata )"oc% o' a 'i"eM

    Inode has 1" bloc* addresses. The first 1< are direct bloc* addresses of the first 1< databloc*s in the file. The 11th address points to a one-level inde6 bloc*. The 12th addresspoints to a two-level double in-direction! inde6 bloc*. The 1"th address points to a three-

    leveltriple in-direction!inde6 bloc*. This provides a very large ma6imum file siNe withefficient access to large files' but also small files are accessed directly in one dis* read.

    208 What is a she""M

    : shell is an interactive user interface to an operating system services that allows an user toenter commands as character strings or through a graphical user interface. The shellconverts them to system calls to the 5 or for*s off a process to e6ecute the command.ystem call results and other information from the 5 are presented to the user through aninteractive interface. ommonly used shells are sh'csh'*s etc.

    218 B!ie' a)o+t the initia" ,!ocess se.+ence &hi"e the s6stem )oots +,

    $hile booting' special process called the ]swapper] or ]scheduler] is created with 0rocess-ID

  • 8/12/2019 SWL Writeups (RachanaS)

    66/76

    oftware )ab T.;.omputer

    getppid! -parent process idgetuid! -user idgeteuid! -effective user id

    238 Ex,"ain 'o!%78 s6stem ca""

    The for*!] used to create a new process from an e6isting process. The new process is

    called the child process' and the e6isting process is called the parent. $e can tell which iswhich by chec*ing the return value from for*!]. The parent gets the child]s pid returned tohim' but the child gets < returned to him.

    248 !e-ict the o+t,+t o' the 'o""o&ing ,!og!am co-e

    main!Sfor*!printfX@ello $orldX!U:nswer3

    @ello $orld@ello $orld;6planation3The for* creates a child that is a duplicate of the parent process. The child begins from thefor*!.:ll the statements after the call to for*! will be e6ecuted twice.once by the parentprocess and other by child!. The statement before for*! is e6ecuted only by the parentprocess.

    258 !e-ict the o+t,+t o' the 'o""o&ing ,!og!am co-e

    main!Sfor*! for*! for*!

    printfX@ello $orldX!U:nswer3X@ello $orldX will be printed 8 times.;6planation32n times where n is the number of calls to for*!

    2=8 List the s6stem ca""s +se- 'o! ,!ocess management:

    ystem calls Descriptionfor*! To create a new process

    e6ec! To e6ecute a new program in a processwait! To wait until a created process completes its e6ecutione6it! To e6it from a process e6ecutiongetpid! To get a process identifier of the current processgetppid! To get parent process identifiernice! To bias the e6isting priority of a processbr*! To increase/decrease the data segment siNe of a process

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    67/76

    oftware )ab T.;.omputer

    2>8 #o& can 6o+ get$set an en*i!onment *a!ia)"e '!om a ,!og!amM

    Jetting the value of an environment variable is done by using getenv!].etting the value of an environment variable is done by using putenv!].

    28 #o& can a ,a!ent an- chi"- ,!ocess comm+nicateM

    : parent and child can communicate through any of the normal inter-process

    communication schemes pipes' soc*ets' message Eueues' shared memory!' but also havesome special ways to communicate that ta*e advantage of their relationship as a parent andchild. 5ne of the most obvious is that the parent can get the e6it status of the child.

    2G8 What is a om)ieM

    $hen a program for*s and the child finishes before the parent' the *ernel still *eeps someof its information about the child in case the parent might need it - for e6ample' the parentmay need to chec* the child]s e6it status. To be able to get this information' the parent callswait!] In the interval between the child terminating and the parent calling wait!]' thechild is said to be a Nombie] If you do ps]' the child will have a ] in its status field toindicate this.!

    308 What a!e the ,!ocess states in @nixM

    :s a process e6ecutes it changes state according to its circumstances. 4ni6 processes havethe following states3unning 3 The process is either running or it is ready to run .$aiting 3 The process is waiting for an event or for a resource.topped 3 The process has been stopped' usually by receiving a signal.ombie 3 The process is dead but have not been removed from the process table.

    318 What #a,,ens &hen 6o+ exec+te a ,!og!amM

    $hen you e6ecute a program on your 4&I= system' the system creates a special

    environment for that program. This environment contains everything needed for the systemto run the program as if no other program were running on the system. ;ach process hasprocess conte6t' which is everything that is uniEue about the state of the program you arecurrently running. ;very time you e6ecute a program the 4&I= system does a for*' whichperforms a series of operations to create a process conte6t and then e6ecute your programin that conte6t. The steps include the following3 :llocate a slot in the process table' a list of currently running programs *ept by 4&I=. :ssign a uniEue process identifier 0ID! to the process. iopy the conte6t of the parent' the process that reEuested the spawning of the newprocess. eturn the new 0ID to the parent process. This enables the parent process to e6amine or

    control the process directly.:fter the for* is complete' 4&I= runs your program.

    328 What #a,,ens &hen 6o+ exec+te a comman-M

    $hen you enter ]ls] command to loo* at the contents of your current wor*ing directory'4&I= does a series of things to create an environment for ls and the run it3 The shell has4&I= perform a for*. This creates a new process that the shell will use to run the lsprogram. The shell has 4&I= perform an e6ec of the ls program. This replaces the shell

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    68/76

    oftware )ab T.;.omputer

    program and data with the program and data for ls and then starts running that newprogram. The ls program is loaded into the new process conte6t' replacing the te6t and dataof the shell. The ls program performs its tas*' listing the contents of the current directory.

    338 What is a aemonM

    : daemon is a process that detaches itself from the terminal and runs' disconnected' in the

    bac*ground' waiting for reEuests and responding to them. It can also be defined as thebac*ground process that does not belong to a terminal session. %any system functions arecommonly performed by daemons' including the sendmail daemon' which handles mail'and the &&T0 daemon' which handles 4;&;T news. %any other daemons may e6ist.ome of the most common daemons are3 init3 Ta*es over the basic running of the system when the *ernel has finished the bootprocess. inetd3 esponsible for starting networ* services that do not have their own stand-alonedaemons. ,or e6ample' inetd usually ta*es care of incoming rlogin' telnet' and ftpconnections. cron3 esponsible for running repetitive tas*s on a regular schedule.

    348 What is H,sH comman- 'o!M

    The ps command prints the process status for some or all of the running processes. Theinformation given are the process identification number 0ID!'the amount of time that theprocess has ta*en to e6ecute so far etc.

    358 #o& &o+"- 6o+ %i"" a ,!ocessM

    The *ill command ta*es the 0ID as one argument this identifies which process toterminate. The 0ID of a process can be got using ]ps] command.

    3=8 What is an a-*antage o' exec+ting a ,!ocess in )ac%g!o+n-M

    The most common reason to put a process in the bac*ground is to allow you to dosomething else interactively without waiting for the process to complete. :t the end of thecommand you add the special bac*ground symbol' \. This symbol tells your shell toe6ecute the given command in the bac*ground.;6ample3 cp V.V ../bac*up\ cp is for copy!

    3>8 #o& -o 6o+ exec+te one ,!og!am '!om &ithin anothe!M

    The system calls used for low-level process creation are e6eclp! and e6ecvp!. The e6eclpcall overlays the e6isting program with the new one ' runs that and e6its. The originalprogram gets bac* control only when an error occurs.e6eclppath'fileFname'arguments..! //last argument must be &4))

    : variant of e6eclp called e6ecvp is used when the number of arguments is not *nown inadvance.e6ecvppath'argumentFarray! //argument array should be terminated by &4))

    38 What is /M What a!e the *a!io+s schemes a*ai"a)"eM

    The term I0 Inter-0rocess ommunication! describes various ways by which differentprocess running on some operating system communicate between each other. Qariousschemes available are as follows3

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    69/76

    oftware )ab T.;.omputer

    0ipes35ne-way communication scheme through which different process can communicate. Theproblem is that the two processes should have a common ancestor parent-childrelationship!. @owever this problem was fi6ed with the introduction of named-pipes,I,5!.

    %essage Cueues 3%essage Eueues can be used between related and unrelated processes running on amachine.

    hared %emory3This is the fastest of all I0 schemes. The memory to be shared is mapped into the addressspace of the processes that are sharing!. The speed achieved is attributed to the fact thatthere is no *ernel involvement. ut this scheme needs synchroniNation.

    Qarious forms of synchronisation are mute6es' condition-variables' read-write loc*s'record-loc*s' and semaphores.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    70/76

    oftware )ab T.;.omputer

    Cuestion an*

    1! $hat is a 04 burst[ :n I/5 burst[Ans&e!:

    F 04 burst3 a time interval when a process uses 04 only.F I/5 burst3 a time interval when a process uses I/5 devices only.

    2! :n I/5-bound program would typically have what *ind of 04 burst[Ans&e!: hort.

    "! $hat is ,I,5[Ans&e!: ,irst-in-first-out Eueue.

    #! $hat does ApreemptiveB mean[Ans&e!: ause one process to temporarily halt' in order to run another.

    (! $hat is the AdispatcherB[

    Ans&e!: Determines which processes are swapped out.

    +! )ist performance criteria we could select to optimiNe our system.Ans&e!: 04 use' throughput' turnaround time' waiting time' response time.

    ! $e can ta*e any one of the above criteria' and optimiNe it. )ist four ways we can optimiNeit.Ans&e!: 4se average' minimum value' ma6imum value' minimum of variance.

    8! $hat is throughput[Ans&e!:&umber of >obs done per time period.

    7! $hat is ,,[Ans&e!: ,irst-ome-,irst-erve.

    1

    11! $hat is the convoy effect[

    Ans&e!: 5ccurs when we have one 04-bound >ob and many I/5-bound >obs. The I/5bound->obs are lined up in a convoy' waiting for the 04-bound >ob to finish up.

    12! $hat is ,[Ans&e!: hortest >ob first. It usually means the >ob with the shortest 04 burst.

    1"! $hat are the advantages of ,[ Disadvantages[

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    71/76

    oftware )ab T.;.omputer

    Ans&e!: 0rovably optimum in waiting time. ut no way to *now length of ne6t 04burst.

    1#! $hat is e6ponential averaging[ @ow is it calculated[Ans&e!: : way of using previous history of a >ob to predict length of ne6t 04 burst.TN K1! G+F tN! K 1 -+! F TN!' where tN! is length of nth 04 burst' and TN! is the

    previous average.+ is the weight factor.

    1(! @ow are priority and , related[Ans&e!: hortest >obs have highest priority.

    1+! )ist internally-derived priorities.Ans&e!: Time limits' memory usage' number of open files.

    1! )ist e6ternally-derived priorities.Ans&e!: ,unding' politics' who' urgency.

    18! $hat is indefinite bloc*ing[ @ow can it occur[Ans&e!: :lso called starvation. : process with low priority that never gets a chance toe6ecute. an occur if 04 is continually busy with higher priority >obs.

    17! $hat is AagingB[Ans&e!: Jradual increase of priority with age of >ob' to prevent Astarvation.B

    2ob with leastamount of 04 burst left to complete.

    21! $hat is round-robin scheduling[Ans&e!: ;ach >ob is given a time Euantum slice to run if not completely done by that timeinterval' >ob is suspended and another >ob is continued. :fter all other >obs have beengiven a Euantum' first >ob gets its chance again.

    22! True or ,alse3 ound-robin scheduling is preemptive.Ans&e!: True.

    2"! $hat is the time Euantum used for[Ans&e!: ound-robin scheduling' to give each process the same processing time.

    2#! @ow should the time Euantum be related to the conte6t switch time[Ans&e!: Cuantum should be very large compared to conte6t switch time.

    2(! @ow should the time Euantum be related to the 04 burst times[Ans&e!: 8obs run in foreground

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    72/76

    oftware )ab T.;.omputer

    bac*ground runs only when foreground is empty' or waiting for I/5.

    2! @ow can multilevel Eueues be scheduled[ $hich might have priority over others[Ans&e!:

    a. ;ach Eueue can have absolute priority over lower Eueues.b. Time-slice Eueues can' giving each Eueue a certain percent of time.

    28! $hat are multilevel feedbac* Eueues[Ans&e!: 0rocesses move from one Eueue to another' depending on changes in its conditionsthat is' the 04 burst may change!.

    27! $hat is the Adeterministic modelingB of te6t[Ans&e!: *etching the Jantt chart for a given >ob set' and determining specified averages.

    "

    F :dvantages3 simple to compute.

    F Disadvantages3 results apply only to the specified >ob set.

    "1! $hat is a critical section[Ans&e!: : section of code that only one process at a time can be e6ecuting.

    "2! $hat is the critical-section problem[Ans&e!: To design an algorithm that allows at most one process into the critical sectionat a time' without deadloc*.

    ""! $hy have critical sections of programs' as defined by authors[Ans&e!: To allow no more than one process in at a time.

    "#! )ist the constraints Di>*stra placed on solutions to the critical-section problem.Ans&e!:

    a. imultaneous e6ecution is eEuivalent to seEuential e6ecution in un*nown order.b. peeds of the processes are independent of each other.c. : process in noncritical section can9t prevent other processes fromentering the criticalsection.d.election of admitting one process into critical section can9t be indefinitely postponed.

    358 $hat three reEuirements must a solution to the critical-section problem satisfy[Ans&e!: %utual e6clusion' progress' bounded waiting.

    "(! $hat variable is common between the two processes in algorithm 1[Ans&e!: turn. &ote that i and% are not variables.

    "+! $hat is wrong with algorithm 1[Ans&e!: ince algorithm 1 reEuires strict alternation of processes in the e6ecution of thecritical section it does not satisfy the progress reEuirement.

    &5;' Dept. 5f omp. ;ngg.

  • 8/12/2019 SWL Writeups (RachanaS)

    73/76

    oftware )ab T.;.omputer

    "! $hat variables! is/are common between the two processes in algorithm 2[Ans&e!: : two-element boolean,lag array.

    "8! $hat is wrong with algorithm 2[ @ow do you prove it[Ans&e!: Qiolates the progress reEuirement see page 1+8!.

    "7! $hat variables are used in algorithm "' which are common to both processes[Ans&e!: : two-element boolean array,lag and turn.

    #

    #2! Define the wa*eup operationsignal!.Ans&e!: :dd 1 to the semaphore.

    #"! uppose we want to e6ecute the statements

  • 8/12/2019 SWL Writeups (RachanaS)

    74/76

    oftware )ab T.;.omputer

    #8! uppose that a system is in an unsafe state. how that it is possible for the processes tocomplete their e6ecution without entering a deadloc* state.Ans&e!: onsider the following snapshot of the system.

    +llocation (a' +vailable

    + / = + / = + /=P< < < 1 2 < < 1 2 1 ( 2