Professional Documents
Culture Documents
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
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
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
else
&num2 is zdln3 Sum)
pintfC Sum 0f num
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
Popl zebP
ret
ese
rintf (Tm the child Protess oith pid and ppdYdln',
getpi dgetppidt)};
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 ?
pdet pdg
cha krtack;
enum procstatt State
Tnt ptds
Struct roc Parentj
Struct trapframe * t f s
chan name[t6J:
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)
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
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
kenel mode
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
2 15
AVg wT BtIS420+2
L
62 15-5
19 ioi by- (Pettnt cPu unge/n)+Base
hee blse -60
ProcessRecertCPU Usage
P
+60
(nes) 18,t0
69
Ys new) 1+60 65
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