Unit 3 Notes Os
Unit 3 Notes Os
Fowcess Statu-
MM
M M STS
( N e w ) T S
Susperol
wit/
RLadlt SP BID MTS
Suye
BnttHEN
Suspercl
dicgaum wait
o but SM
SH).
stala
S u L f e a
vasioug
eugh
The oceLs passus ui abet
stah , Hhl pocws
Ctateol, t
n is t d
0 N oeateel,
be ceat but notHeE
picked b y eHhe
t n SoH pitkedTby
ROhich
Hhe pro9ham
catiHHeProAR
0So a prupa
pot,
Ht Creating a
Ate S
s tta
at e
Rady enter& he
Hhe
lady
Pw oadeo
nto
he id Teady
Hhe poDceL Hhat
av
a n e ody
ie eAL fn a
nmmDrY maintaind
Maun .
&nRaIL
ex ecutf
fos
ii choseh by
TL poocLs
An aUd
3 Runhi vq fos ex
ecutf
CPU executed
du
He f s t u c t i ens
(4) Ot Blaked- Whenuwes H proceAS UHOts
acceA to /o
uhput yem Hh uil) it eters H
uwait Block state P 0 s Conttiinul
to wait wn he Main memy avo
doe o t dLeaui re CPU Once ID epeoton
Pfosmed r complettd H poces Goes
Lady Statt
ad Stat
ua
-Prcs hat
Suspend Koody
in Uady Stak
but
m
meau
inn muma
Enitfaly &ut om
Swapped storage
w e extena
Srtto
s u s p n d Racdy
Placed Keady
be in
s a f l to
and back to feady
prOC gves
Stat T
Statr whon m
awcula ble
SchedulA
Aschedul aa type o Stem 9tun
Hhat alleus o hand potoL
Schedulng
TUl au 3 types e ours Scheoul,
Shes
L e n a Tetm Te
Scheclule
Tem Schedul
Sehoeuls
short Tem C
Long Tem Riady PU Procas,
SCodudn", Sudeddul Tenvat
(Ccne
om
SeAOrdoh
T]odwia
Buout woihg
Context Switchi.
Contx switu H h i swtcie u
CPO om 8ne poceK p a n e h ProcAR
LOmdert Swtching
Sewel aoos A C x e c L
TnteupSelen Peoos
hneLo p2oce8 So Het Saue state ivtofra
Old proc Can Oa Fselated statetabm PB,
PxecutL Hhe shmu
get
while anoh p'abt e . 1 0n hold
Obfet'ves
(PU uslizakDn
() Max.
) feü .Ubatton of (P
(ui MaY lhunughmut
Minimn u a l b g Tmo
( T) Tm at whih pates
ornpleti'on Tim
npletu e x e u i n
DRPONse to Hhe
lpens e
tfme i 2*od
bette o
Highs thLouhpt
Petomance
()R T T
Fst -
O Teme
P3
PY
PS 3
P3 P1 Ps P2 Pi
2 |3
CT A w aT-BD
TD.
(ToA:T-BT)
PL -3= 4
8-3S
P 3 13-S=8
2-0 2 2-2-o
P3
9- 8
Py 14 Iy-5= 9
PS10 I0- 6 6 3 =3
=5-8 wnt
4t8t2t9tC =29/
AvgTA T =
5
Avg T -OtS+0t8+3 32 uut
Pobleha CPU BLt Tem Supfosee Hat
Padcerd asHivd
3
Py en Hhe qulut
P3 Calclat
w:T 9
P2
P I7
Gcutt Chast
Soln
PyP3P2P
29
2
Ot3+8t12
CT T-T wT =
Avg
Py 3 O
P3 8
P2 12
P 29 12
Acuarctages,. tor
( c i t , notge
does ot dead to Stavatien. ePu)
easy to Lnoli-tand
saduavtagl
T means
Sulhes e m Convoy efect
ave hg bust +ima aaive
a poOC8
bu&t +ime
hanHhe S m a l l
waut
engtime +o9
CPU
)STF (Shorteut Job Fist) Schaduling
CPU ii alignsad
n SJF Schedullng , 4 u
smallst bukt
H pooces having
tme
S3F nen- preemPive algo
alg0
P3 using SJF 9
P4 6
3
PS
12 16
PS
PPS
PS
Ag.T-A T 4t1SS76tH0
Prust id CT T-AT wT
4-13 S
P 7-3y
8it
P2 6 G=IS
-2-3
P3 G-y
6-6 0 Avg-wT. 3 t l 3 t D t T
Py 6-06
2-2=1d b-37
PS12
4-8uit
-2
woittnq m e usiva
Calulat aw
STF
BuystTim
PvocNb Arrival Tmt
3
PI
2
P3
Py
Gnaitt C h a r t -
oln Py
P P2
P3
1 py
P P2
P2 Py
w T
TA:T
CT -32
6-1S 8-y 4
P1 6 lb-2 8 2-2 0
P 10
3
3-1-2
10- 6
P3
3 wd
P
+4t0t6
Avq. w T
4
Frst) 8
TFme Hst)
Tme
Remalntnq
Shtest Pseemplien
with Pseenplien
3SRTF STF oth
aL
ChADnu
also
prremptive i n nalise
algo.
Calculate avg
BT
ouaidd AT WT aud
Regpens TPml
P 3 Oeach pocets
P2
2 using SRTF 9
P3 J
Py
Gnantt haurt
Solno PP2 P2 PPYP:P
L
P1
P PI4 PI4 P3y
P2-3 P2-2 P2 P2
2 P34 P3 Py-| Rsponie Time
T AT
wT R T - CPU fist fm
CT - 0-DO -AT
- 9
P 3
3-3-1-
1-y- -2 7
#0
P2 13
4-1
5-y
13-2 1 -104-4
4-4 70
0
P3
5
P vg.w.T=4+0t*70 -7S
KsPenle Tme
P2 0D
P3+
PY 0
howssTd
ATT BT Calceloct
aug T A.T,
Pootlena 3
P awq. T
1
P2 2 Cwa. R T
P3 usng SRTF 9
P
PS
a ctt
Sol
C h a s t
P2 P P2 P3 PS P
P
8 6
PyS
P24
unlt
hvg. T
P T =}
3.8 wnit
Avg WT =
l'6 wd
Avg 0t 0 t2tot6-8
=
Pvg
Hvg RT
Advatas8 uhantees
quhantees
minimun
minumum
optimal&
SRTP
(
waitfng m
sadvateage4
yatienn
sBa
l a d s +to tor a foDCeLiep
Canot
be set
Wasuge bust fme
odtieA
Pi
hawing
ml
Am.
(ii Poor
UuipeNLe
hawe
T
FC FS Schedulig
pseempHve mode
n
best perfoomanct
Advantane T ve timl.
Advand auvg uiponse
telms
Ttme Shaliy System
isadnvtoei) Leade to staAuaten.
( Pesfo-smant is deped S n
Tme Cuantu
iorih'es Canot Set or t
PoOCoALel.
quandum
-2wtt/
u os Td AT BT Th Hme
Calclatr awg waittg
5
PI dti'm, awg. TAT&
P ufng
P3 2 awg. R T
RR Seduling allgo
P
8T
P2 2
Ps2
PrPAPrpp
Readu
PPP P P
Cantt Chasty
P-ots d| C T TA T T RT
2 2
P
10
P 2
y
P3
S
PY
12t10tytS=+4sunit
T AT
T=tb+2+y 4 S wr
hg
Av RT =
AT &T T uAt
P
Avg TAT : 2
P2 AvG T 9
P3 2
4 3
PS
Sdn
Pl P3, P2, P
Raaly PS, PI, P2, Ps, Py
Gpantt Chaot
PP2PsP P PSP2|P1|PS
02 2 2 13 1y
Avq.TH:T 13t11t3tAtlo 86
uwlt
4+14tDt6tT 8.2wit
PNG. TA T =
5
WT 0tl +9 tltS 52
Avg
okose AT
Hu set e s prbcoRseS
Ceniidu
TA:TL A9.wT.
&B:T ae Given alulat hq
etoiy Ppecphiue schucuulin.
wtng
A T B1 Paioity
P 4 Granitt Cast
P2
P3 2
P 3 PI P2P Pu PsP2P
2 8
PS 2
Phvg TA T =76wut
Hug w T =L 6 uhut
UNIT-3
Thread:
A thread is a flow of execution through the process code, with its own program counter that
keeps track of which instruction to execute next, system registers which hold its current
working variables, and a stack which contains the execution history.
A thread is also called a lightweight process. Each thread belongs to exactly one process and
no thread can exist outside a process. Each thread represents a separate flow of control.
A thread is a path of execution within a process. A process can contain multiple threads.
Process vs Thread?
The primary difference is that threads within the same process run in a shared memory space,
while processes run in separate memory spaces.
Threads are not independent of one another like processes are, and as a result threads share
with other threads their code section, data section, and OS resources (like open files and
signals). But, like process, a thread has its own program counter (PC), register set, and stack
space.
1 Process is heavy weight or resource intensive. Thread is light weight, taking lesser
resources than a process.
2 Process switching needs interaction with Thread switching does not need to interact
operating system. with operating system.
3 In multiple processing environments, each All threads can share same set of open files,
process executes the same code but has its child processes.
own memory and file resources.
4 If one process is blocked, then no other While one thread is blocked and waiting, a
process can execute until the first process is second thread in the same task can run.
unblocked.
5 Multiple processes without using threads use Multiple threaded processes use fewer
more resources. resources.
6 In multiple processes each process operates One thread can read, write or change
independently of the others. another thread's data.
Advantages of Thread
In this case, the thread management kernel is not aware of the existence of threads. The thread
library contains code for creating and destroying threads, for passing message and data between
threads, for scheduling thread execution and for saving and restoring thread contexts. The
application starts with a single thread.
Advantages
Thread switching does not require Kernel mode privileges.
User level thread can run on any operating system.
Scheduling can be application specific in the user level thread.
User level threads are fast to create and manage.
Disadvantages
In a typical operating system, most system calls are blocking.
Multithreaded application cannot take advantage of multiprocessing.
2.Kernel Level Threads:
In this case, thread management is done by the Kernel. There is no thread management code in
the application area. Kernel threads are supported directly by the operating system. Any
application can be programmed to be multithreaded. All of the threads within an application
are supported within a single process.
The Kernel maintains context information for the process as a whole and for individuals threads
within the process. Scheduling by the Kernel is done on a thread basis. The Kernel performs
thread creation, scheduling and management in Kernel space. Kernel threads are generally
slower to create and manage than the user threads.
Advantages
Kernel can simultaneously schedule multiple threads from the same process on
multiple processes.
If one thread in a process is blocked, the Kernel can schedule another thread of
the same process.
Kernel routines themselves can be multithreaded.
Disadvantages
Kernel threads are generally slower to create and manage than the user threads.
Transfer of control from one thread to another within the same process requires
a mode switch to the Kernel.
Difference between User Level thread and Kernel Level thread
User threads are implemented by users. kernel threads are implemented by OS.
OS doesn’t recognize user level threads. Kernel threads are recognized by OS.
If one user level thread performs If one kernel thread perform blocking
blocking operation then entire process operation then another thread can continue
will be blocked. execution.
User level threads are designed as Kernel level threads are designed as
dependent threads. independent threads.
Multithreading:
Multithreading allows the application to divide its task into individual threads. In multi-threads,
the same process or task can be done by the number of threads, or we can say that there is more
than one thread to perform the task in multithreading. With the use of multithreading,
multitasking can be achieved.
The main drawback of single threading systems is that only one task can be performed at a
time, so to overcome the drawback of this single threading, there is multithreading that allows
multiple tasks to be performed.
The idea is to achieve parallelism by dividing a process into multiple threads. For
example, in a browser, multiple tabs can be different threads. MS Word uses multiple
threads: one thread to format the text, another thread to process inputs, etc.
(2Reocllpek dwetelovtl t
set
ndes maintoinivg a
This St oategy "madt
modt
a dicision d
olh
dato uig
wing
enttain a
tr
nou) &ugust nib
wluthe do SoquRt
CaLulel
hlu
entutaivuq Hhe
move A an wntale Statt,
Hhe
he Syetem to
it i dii casded
Banket's Algooithm
speifiestHil
no ef
U u b u s c e type
e tlat
Allocat'en
Cach
proePoDse
alloattd to Hh e Cack
been O
is the
Neeod:- Max that a
dUouAE
Max Juiouses tupe
pooCoys coh LcGut
pe a t o
PnetarcaR
to
tollouos a Sal-c Algo
banuess A1g0
UuR ulbvg
stat t laf
check coutus ht
Statt nt
evctest o i sale b ut allo
allo c a t he
cati
Hhen
Tf ut is a Safe stat1 Otha
UuiousListo
tepotte
uegusteol
pseuieus Stite
t Siollback Bo fk
wfse
to be in
Sygtem soid
Scefe Statt eprCLL
Cah be
Ohen ll
LOIH
SequenCL L OIh
Sae stote seguOnCL
09ubitauySDm
ed u
exeiuct
wmbe o
awoul lable
he
32+ J2 o 0]- Al t2
NewAvailate-[3
5 32
No Pu ud
olvol
satisdied. Py Succers fully executed
Qtes ex ecuctibn eultoLe SusouCa
Neuo. haike:-532]t L2 t3 43]
NLo P i SucceLdfully ex ecut eo
Pvouilable -[7 y31+ [oo 2)
L+4S -
N Gu P, erecuta
AvoilaHe L14s]+ [o 1o] C7 5 S
P3 execut Sekceevsul
Seapuenct
PaPyPs > P ->Pa
Sae sequonee and
s
So,
t a
Occus
wil not
oLlock
oll8wi Snapshot a
Quas& Cened He
System
AllocaiCn Max Aveulade
ABCS A BCD
ABCb
06S6 620
o0
P O632 O6S2
Pa OO2
O O12-
T7S0
reod mao)x 9
notc mablk
ert e
Ohat iu He cont
i n Sale stete9
a) Sale state 9
in
Hhe suelem
b)Ts
(
son Need Max- Allocatb
Need mat.ix:
A_B D
66 4 2
20
OO 0O
P
0 5 0
NO
P Io 6 4,23 LI6
Loo 2o1 SLi6 2 03 Ye
P2
lable=vailable t Allocahen
Prvat b 020
6 2.0)t (
L 6 40o
Loooo] < Ci 6yo Ye
i64e
hvouilable I64o)+ [o o o]
o -