You are on page 1of 16

Horne- Assignment (to-2)

table
S t the main in fovmation in the useh Struthune and process
entry Tn which struckune docs UNIX V6 albrate the keinel Statk) Ho
many of tbese Strutkwres does ik allocate)
The kenel has a protess table where it stoves the data of
A) Ctate of the protess ancd oher information about bhe protess. The
information of Bhe tntry ond the u-anea of he pro Less tombined
s the Context of Bhe process
Set of procesS Stakes-
in useh mode.
) Extcuting
in kehnel madle.
i Exeubing
i Ready to run.
Sleeping in memor
Ready to un, but in Suap space
vsleeping in Swap spate
vi Preempted
yi/ ely created, Not readyru nor slpeping-
State.
executed exit Sy!tm call and is in the zombie
Process
The Ve kenel stack for a given protets is located in the u ahta

for that proces A proess's u-ahea tonti'sts ef the kehnel statk


anol the uSer Structuhe.

|Suppose a process goes to sleep and the System Contains no protess


veady to run
what happens when the sleeptng protess dees its
Context Swttch) In xVg, explain the design of sleep, Sys. sleep. keup
wakeup1
A XVG provides cleep and wakeuP funchons, that ahe eqyuivalent to the
wat and signal -funcbons of á cond?tional vaniable. The sleep and
Akeup funchons must be învoked wikh a lotk that ensures the SleeP
and wakeup pocedures ane Completed. onte the Sleep funcbon call

Context Switcked out The tontrol vetudns batk


the Schedule it is
the proLess has been twokenup and tontext
To this line, gnte
-that time, the Sleep tuncbon
Sitched in by schedulen again t lock and re tuns
his special ock, teacquives the original
aes
batk in he tooken up protes

Sys.sleep Protess
given yeu
usingO this funchont alos 6pu to teiporariy
not to intufere oith more importat
(ot riority ond hente
foegrourd tasks
Syntad
Sys leep(time
execubon tor, in seconds
timetime intehval to susgend

3 Explain the design of algorithrns : inthand, Suytcall


Round robin, ALFQ Stheduleh: briefly explain
A) Inhand Algorithm

Save lpush) hhent Context


layer
detoimine intemupt sourte
Call mtavuot handler
restove pop) previous tonteat layen;
Input-one

Output- None.

Systall Algorithn
Input System call number
Outut esult o-f Systen calU

fnd entry in Syt tem tall table tarreording to sys call runey
detesmine ro-of Panamebehs to Syt call,
CcKpy Parametes fvom ufa address,
Save e n t Context ¥or akortive retun
invoke Sys call Code in keanel
if (ewor during executon of Sys call)
Set register o in User Saved reg ister contex to errov numbtr
urn on (avy bit in s register in user Saved egister
ontext

else
Set reg'steri O, t in uSer Saved reaister Context
to return values frorm System call

Round Robin A Small quantum reduter the response bime for all
qoeses, which is important tor inteacbive protesses. Howe ver, a lona
Q uarturn reduces the ovehhead of process Switehing, which intreajes
rughput and tPU utili zabion A short quanbum iusehl for a
ereval Puspost tamputer A leng yuanbum useful tor a batch Systo

MLFa An t/o bound 7r0tess is favoured by ulbilevel feedhack


will be vmoved
qutuing schedulen becouse jobs that ure cpu heavily
fospriority aueues. This will leave the I/o bound Processes in the
higher rio riby yueues
4write a Sygtem Prograrn that accepts two Smal rumbens (iT) as
07guments and then Suns the tuwo in a child process The Sum should be
rebwned by the child to Panent as tts exit status and
panent Should
Dint the sum.
+ incude <iostream
#incude <Stdioh>
t ineude unistdh>
int main()
int Sum
int numy num13
zfovkC)
if (no)
pintfC" Enter num!: ")
Scanf ( Yd", &nunmt);
pvintf C Enteh num: "
Scanf Y d , knum1);
Sum- num1tnumij
printf ("Sumof numi& num 1 d ]n') Sum
exit lo)

else
&num2 is zdln3 Sum)
pintfC Sum 0f num

Exblain Context Switch in xVg wrt *apt, tapasm.s,Stal c and


Sutthrs.
A) Floto of tontext Switch
Tnvoke the inttbnupt
i Invoke the schedule
i) Stant the Context Switch.

trapasmS
Saves
physcal address of the Segment ofset
Seqment regtster
Set up data Segment
movwSEh- DATA c3), za
movw 7.ax ads
movW 7:aX, zesS
#Call trap(+4)
pushi zesPs
Call trap
Then in trapc, callinA yield to invoke Scheduler
suite
Also after invoking stheduler, he system stants Contert
*ne)
Said before in suwtch( Struct Conteyt old, struct tonteut
Swtchs
movl 4 (KesP) Yeax
movl 8 (resp) .edr
PushlebP
PushL 7-es
Pushleb
Pushl zedi

movl 7esp, (eaa)


movl edà Tesp-
Popl edi
y.esi
Pop
Popl ebx

Popl zebP
ret

)Processes provide Context Explain what tonsbitutes a protesr. Ltst he

tatks performed by fovk Systtm call.


A Sustem calt forkc) t ustd to Create proeges It takes no

aquments and retan a protest ID. The puhpose of fhrkt1t b


Create a neuw process, which betomes the child prstess Aftera
newchild Process is trèated, both procesges witl execute the next
tnstrucbon following the forkt) Systemcal.
14 forkt) rebuhns a negative value,. he creakon of chd
Proess uas unsuccesfal.
forkt) vehunng a zeho o the neuly created chitd proces.
forkt) etunns a potive, value', the Protess ID efchild process
to the Pahent. The retuned rocess ID s of
type pid-t
detined in Sys/typesh
getpidc) s. wed to retrieve the processID assigned to the
Process-
Sample Program
incude <Stdio.h>
tnt main)
int pid and pid rdtn'
rint+("m the ovignal rotess twith pidl
getpidt),getppid;
prd-fovk(
if (pidt-o)
the Povent protes with pid
and ppid 7d|n"
Dvint fCm
etpidt),getprd t);
intf "My child's pid is dtn" p:ds

ese
rintf (Tm the child Protess oith pid and ppdYdln',
getpi dgetppidt)};

rint fid 1d teminakts}n" getpidt );

) n xV6, Eaglatn Scheduling ohameters and untrolling Procesr Priorite


Ustng Swtcht ), yreld t), shedl)
The Swteh funthor does the job of
Contexts The
Switdhing beween hod
stto of pushing' regts ers imb the old Stack
Xaety Stmila td the Step of ves toving Tegisters from he new
Statk, becaute the ntw Statk was also
treated by Swtth atan
eanlien Kme The only tme when the tontext
pushed by Sotch i when a process Structure not
is Creattd for the
first bire
XV6 he sche dulei runs as a
Sepanate thread with it oun
Statk. Theebve, Context Switthes hapen om the kernel mode o|
a running Process to the Schedulen thread to
the neuy process it
has identhied. As a result» the Sswtch
fun cbon is calle d at wo
places:by the schedule toswtch frorn the schedule thread to a
ioand by running proceis that wisher tbgive upP he cpo
ne ched A runming
*oless aluayi gives up the tpu at
he funchbn
his call to Sutch and always relumds extubon at this peint at o
(aten bme.

when
a tiner interaupts occurs and it If deemed that the proce nT
h run for tolong,the brap funtbon alli yield uwhich in tuvn
Calls Sthed
Rourd robin Schedulers normally maintain a Iist of al runnahle
protesef, with each protess exacHy onte in the lst what uould
hapen if a proces oturnd twite in the t ?

Al If a Procesor Ccurs move than once in the Ound-robirn ltt,


ben it wi get too turns for each Pass through be 1tt Ore
reason for allowing this twould be to
implement Pimittve a

Priorty Sqstem ste the move tines it occurs on the 1ist,the


hgher theAcentrge of Bme he pU will Spend on that process
Does this algorikm gve be
kqhest priority to neo process
Ts ths algovthim Stavaton treij
diScuss whetber thi's
algorithn if faiv to all ?rocestes
The algpribm doesndt give the highert ptority to nes Preces.
Even i cxeuubng rocesges took muth ess than 2 m toexecute,
,
the stheduler wauld alteinate blw "neo" and "old precesses,
giving eaqual priority b both. (Given hat executing rotess took
muth longeh than 2ms to execute, most "ne proteses will not
et scheduled duning 9m on he "nts" queue and will then
drop to the bottonm of "old" queue.
es, this algovithm ts Stowation free. Because the Schedulez
altnaber blw tuoo queues, eveny job that is not executed frorn
he ew" ouue eventu ally ends up in "old" aueue
NO,it t not fair to atl ?rOcesses. Some lucky "new"prdcesses
coll get to execut when they reach the top of the and"ne queue
to the bottom pf "old" ajueue have bo
while 'Some toill drop have to
eaecute These protesses must Liait
wait much longen to and wilhave
Processes older han them to compleke,
for all the them as well.
6r the protesges younger than
to wait
has 2 stackS7 what ahe the lonuPtuol
In xvi, why ea ch proess
moves while being managed b
uwhfch a protess
Stages through move threugh
"Deseribe hoLwa prouesS might
Openating System) tuncbon.
vahiouspro ess States. Explain struct proL,allproc
Each process has 2 statks
user Spate Statk.
used shen execubng useh
tode.
kenel spate Statk
kehnel Code.
when execuhng
uSed
which prolef moves
Stages through
and tetminated
eu
rea dy running, wajting
inp. the running state chen it is chosen fobr
A procesf moves
lxecuted by one of the
exeeuhorn The proest's instruchons ane
cpu's of the Syskem.
the attess 0+
memoru, handwane and resources, the
To get
change tn the rocest has to be dene
Struct proC
Strutt prot
Unit Sz

pdet pdg
cha krtack;
enum procstatt State
Tnt ptds
Struct roc Parentj
Struct trapframe * t f s

Struct tonttxt i onttrts


yordchan'
int killed
struct fle o4ile LwoFILEJ;
Sttuct inode * cewd

chan name[t6J:

Allproc To create the first process, the allproc funch'on is uwed

alocate o prot Struchne , muth like


tn rk. Next, the trap
to look ike the Proess entountered a trap
rap
frame is hand-cveated
it memory
vight on &he firtt instruchion tn
tite the c-stjle illuminabon ofF be Part ot the shell program
Inualving the use of tork, waitpid and exerve.

Forkt
THa funtbon wed bo treate a process tron ofhin a proces,
The resutant nes process createdby fork) ts knouon as child
rocestes tohile the ortainal Procér becomes Pahent
The furicbon fork t) t colled one, but it retong totce. Once t
tebuns. fn e Pahent ?votes while the Second titme i t vctums m
the child rocess
Sianatune of forkt)
Pid t fovk tvoid)

Execvet It executes the p*°gram Pointed to hy frlename


The execve funthon is most Commorily used to ovenlay a
ocess image that kaf bein createtd by a call to the fork
function.
int execve (onst Chaht path, char tContt agvr);
wart pidt) For the Cases, whene
a paent ptocess hat more
than one child processes thene it a funcbon taitpidt)that Can
be sed by the Ponent Process to qyuey the change state ofa
Pahticwlan child
phat wartprd (pid-t pid, int *sfatus, int options),
and Processer Creation
1Mustrate UNTr Syrtem b0ot
1 f
the Drocer binginga omput
4)Bootstra?ping s the fhal name for
and making 1t ready tor use
System to fe for all unix Systtms, althoug
The hasie boot process
is veny Similah
used b acompsh 7E vahya yuite from Jystenbt
he mechanisms
øn bolk the phystal hardware and H.
System These
mechanims depend
The boot Can be inibioted autbabicell, raticall
ophabng system polesS
when the twmputeh is Ouered on (or) a
manually and it begin con

esut of boot
ommand from arunnirg Sys3tem.
UNEX boot qocess phages:
Basie hotrdewahe dettebion
Exeung the fAmuware System ni talízatfen program
Locabng and unming he initial boot 7Ogram usua ly fromn
reduteimined lotabon on di'sk
. Locating and Starbng the uNLY ketnel. The kehnel image hle b
exeCube maybe deterined aubmabically lor) via input to the
boot progran.
The kernel inihalièes itself and then ehforms final, hiok kvel
hahduahe checks, loading device and (or keknel' modules as equivd
The kehnel stahts he init ptoLess, which in tutn stah Sustem
pro tes and iniialiis all ackve Subsystem. when evenything 8
ready, the Sustem begins aceptng user lgins
2 Tn xV6, eæplain Sutch tuncion that doesthe jobof switching blo t
conteats, an old one and a neuy one The Swtch funttion it aled
at uwo platei what ane they?
AThe Swtch funcbon does the job of ssithing blw too (onteats
The step of pusking registers tnto the old
is Simlh
statk exactly
to the Sttp of vejtoiag rgiaks tom the new, statk, because the
nw stack was also Cteated y Su tch
at an earlier time. The only
time whn the Context Structue s not ushed by swtch is when a
Pvole Ss is created for the first time.
Tn a scheduler, it runs as a sepanate thread wth its oun Statk.
Therefort, Context swithes hapPPen from the kernel made of a
ruing roce ss to the Stheduler thretad to the neo rotess it har
dentificd As a result, the swtch funthion is ealled at too Plane
by the stheduler to suwtch fhorn bhe Scheduler thread h a new
protes ard by runing Protess tat uishes bo grve uf the cPu in e
huncbon Shed. A running pocesf always qives uf the tpu at this
tall oto
call swth ând aluays reSumes raeCubion at this Point at o
latth Bme.
Jrite an algorithm fov a Sygtem call that makes paent oaitt and
13twrite

tollect the tehmnation stakus of child protest


aitwaitU is he System call hat makes parent wait and tollect
A)
the temination status of thild process.
Algorithn:

create a Child p rotess using fork System call.


I f vetuin value is - then
a print Process Creahon unsutesfu
3 Tehminate uling exit Sysken call
4)Tf retunn value is o tAen.
a) Suspend panent process unail child tomplekes using toait syskem cal

6)Print Pareit start


)printahent endt
5 1f rekuan value is o then

a)vint "child Stasits"


) Print child end'
) sto
1u)write a program that creates tudo child 7tocesses Each created Procerr
has to exeutt o Sefanabe execukable Prog am Make poent process tait
untl both child processes ane Completed bebre being teminated

A procesr. I t kas t» be called to


fork t) is used to create ckild one,

reate tuwo (hild pOCeS$es


rogam
inla de <stdio-h
intude <unistd.kz
in lude < stdib h
int maint)

nt pids
pidl-forkt)3
it (pid.co
pvintf ("n Eor")s
exittt
elte (pide=o)
Im he child prcess 3
vint f" Hello
prtntfl My pid igetptdt))3
exitlo)

elSe
peintf C Hetlo tm the pahent prolers*)
pintfCy ackaal pid isgetjidU;
eit)

TO make pahent ?rocess to tait until the execution of tusa thild P'oenr
to get tominated e have t use Cait() Systm tall. Afte thein
tesmination, Pahent ?rocess Contbnues tts execuöon.

Tn XV6, h0t
data Struckures, funtb'ons and
Sustem call tworks? Lt the
5
files that are b be manipulated How do System (alls relate tbr os and
to the Conte?t of dual-mode

A ASystem call is way fov Program ts interact with the opelabry


a

imakes & System tàll when it makes


a
System. A ComputerP*ogram
Ha
veayuest the ogeaing System's kenel 1t provides an nterface
proess and opehating Systern o a loc user-level Proce ses tb request

Senvitesof oehating Syskem.


Sevices Povlded
process (reabon and anagenment
) Main memory manajement
File Actess,Directory and file Sysktm anagement
4) Device handting (1/0
5) Protechon
NetuorkKing
Ynes of Syskem Call:
forkti,titt), uait( ).
process tontrol
le management opent read, writet),
-
closeC).
2)
Device managenentreadl), wvitec).
4) Infrmation maintairante -getpidt), sleep)
Communication pipet1
Sustem calll ane used in oritext switth w he usetnmade nd

kenel mode

t)Explain the algorithm for Drocets termination.How the kesnel treats


Zombies and orphans
procest Tehrntnabion
Process is tehmínaked by exit sy ttem call.
Enters Zombe Status
Relingish resourte
Buffehed output rekoin to disk:
dismantles its tontext exept tr ts slot inprocesn table,
Syntax: exit(status);
staas: The Value, rehuoned a parent Process.
Zombie, A ProCess which has tnithed the execubon but shI has entry
to its parent ptocest ir khocon a
in the protess table to report
a

ombie proess. A child.process irst beconmes Zombie before


a being
emoved from the proues table. The anent proes rcads the ckit
Stabus o4 he thild proCess whith remues He Child procers entry
from the protess table.

phan A rocesS whose anent ?tocess no more txi'sts ie eithon


ftrishe d (o) teninated wlthout nitng f its chila Proces t

teninate is called an ovphan protess. init prolesS, once it


Howeveh he orphan Process
is soon adopted by
yaent Procest dies
Cive Surm
7why er-process kehnel Stack Explain Stheduleh() n xVG Summg
f entry in XVs P¢B
A) exeute User Code on usea statk in the uSer Porbion of .
Processes
Each process has Second keinel Stack
procets virtual address Sfate
its own stark Jutt like tes,
Kehnel Spate. renehally each thread has
as td bea Sepanate Place for each 7 wtess to hold i Set bf Saved

Egistes each process also needs ts oun keinel Stack, b wok as it

execution stack when it is executing tn the kehnel.


the prionfties and assign the Proesses
to the (P
Schedule ) uses

baJed on the rioitbieg.


Scheduling gori8km
witha runnable roes.
Find he highest -iority utue
-

Findl the fiMt proters on that. quue


Calulabk 't quanbum SiZe
Let ft un
- when i bme is up ut it on bhe expived 1st
Repeat
have protetes that
)Thehe is a bitmap indicabrg whith ueue
the
ahe uady to run so cpu allocabon) is done bated on
of aueues kaving he processes in ready b vunState
Priovibies
)A pB( Proress Control block) tontains informaton about the Process
ey egistes, qyuantum, prrority ctc. The proress table Qnavndy
o pcB's that means logically tontains d p¢B foral of the

Cuwhent rotesses tn he System


) where is usualy Round-robin Jcheduling used? what priofty
Schedulirg? reblem?
and stahvabion
ARound-robln Scheduling s Sinple, easy to implement
free Rourd-robin Stheduling can be applied tb othen stheduling roblems

Such as data Scheduingih lomputer nebiorks.


Packet
Prioiky Stheduling Thrs stheduting algorithm assign e cpu tothe
Oce sses based on the qrority of he 4ueue and gien tonditon
Protess P
Burst time 15 5 1o

Process AT BT CT TAT WT
O 15 15 15
P
5 2D 20 5
27 2 20
16 3 3 27

Ready queue

nantt
Cht

LP7L 7 12 19 7 24 24 31 35 37

Av TAT I5+20127 +37

2 15

AVg wT BtIS420+2
L
62 15-5
19 ioi by- (Pettnt cPu unge/n)+Base
hee blse -60
ProcessRecertCPU Usage
P

New Horities ane

+60

(nes) 18,t0
69
Ys new) 1+60 65

The Sthedule lowers the


relabve prioriby of pu-bound Proteses

26)Explain the funchion sthed used by oa Process that wishesto


relinguish he cpu* How does xVs store rocess table'! Houw doef an &

keep tine
A A rocess that withes to relingquith he c?u callt the funtbin
Sched Thishuncbon triggers a tonteat Swith and when the ro
is Switched batk in a taten ime, itre sumes txecubon again in
Sched itself. Thus a call to Shed freezes the tXe cubon of a
proters tenmporarily
XV uses the follouwing nameS o protest States : UNUSED, EMERYD,
SLEEPtNGn, RUNNABLE, RUNNTNG, Z0MBIE The Proc Strucbvresane al
stoved in a tinked lst Evehy tpu has a shedules thread hat call
the Sthedulen funchon at the stant and loops in it foveve
when you tonnect your Conmpukr toan inteinet
(onnection,the
OS will go ffnd a bme Seven on the netuiork ond query he te
Sve fov uhhent time The of can use this to vey auwvatey set
Your Conpuuter's total clock. This uses Netuwork Time Proto col, aled NT

You might also like