Project Report of Operating System
Project Report of Operating System
Project Report of Operating System
&TECHNOLOGY BHOPAL
SESSION 2010-2011
SEMINAR/GROUP DISCUSSION
On
OPERATING SYSTEM
SUBMITTED TO SUBMITTEDBY:-
PROF. SHAHEEN AYYUB IND RAJEET G OUR
What is an Oper ati
ating Syst
System
Cont
Controlli
rolling
ng the
the comput
computer involves sof tware tware at sever al levels. We will differentdifferentiiate
ate
k er
er nel services, libr ary services, andand a pplicat
pplicatioion
n-level services, all of wh
of whic
ich
h are pa
par t of
the
the oper ati
ating syst
system. Processes run run Applicat
Applicatio ion
ns, whic
whichh are link
link ed
ed together
ther with
libr aries that perform stan standdard services. Th The k er
er nel suppor ts the the processes by
providing
providing a path to the the periph
peripher al devices. Th The k er
er nel respon
responds to service ca calls from
the
the processes and and int
interrup
erruptts from the
the devices. Th The core of th
of thee oper ati
ating syst
system is thethe
k er
er nel, a cont
control
rol prog
progr am that fun function
ions ini n privileged state (an execut
execution
ion cont
contexextt that
allow
llows all hard
hardwaware
re instruct
ruction
ions to be execut
executed), reareacting to interrup
nterruptts from ext
exter nal
nal
devices andand to service request
requests and
and tr a ps from processes. Gen Gener ally, the
the k er
er nel is a
perman
permaneent resident
resident of th
of thee comput
computer. ItIt creat
createses and
and terminat
erminates es processes andand respon
responds
to their
their request
request for service.
Oper ati
ating Syst
Systems are resource managmanagers.
ers. Th
The ma
main resource is comput
computer ha
er hard
rdwa
ware
re in
in
the
the form of processors, st stor age,
age, in put
put/out
/out put
put devices, commun
communicat
ication devices, and
ion and
data.
ata. Some of thethe oper ati
ating syst
system fun
function
ions are: implement
implementiing the
the user int
interf
erf ace,
shari
haring
ng hard
hardwa
warere among
mong users, allow llowing users to share hare data among
mong themselves,
themselves,
prevent
preventiing users from int interferi
erferingng with one ano
another,
ther, sch
scheduling
eduling resources among
mong users,
f acilitat
cilitatiing in put
put/out
/out put
put, recovering
recovering from errors, account ccountiing for resource usag usage,
e,
f acilitat
cilitatiing par allel oper atio
ationns, or ganizi
ganizing
ng data for secure and and r a pid access, and
and
handli
handlingng networ
twor k commu
k commun nicat
icatio ns.
ion
Moder n Oper ati
ating syst
systems gener ally have
have follow
following three
three maj
major
or goals. Oper ati
ating
syst
systems gener ally accomplish
ccomplish these
these goals by runn
runniing processes inin low
low privileg
privilege and
and
providing service ca
providing calls that invok
vok e the
the oper ati
ating syst
system k er
er nel in
in high-privile
gh-privilegge stat
state.
e.
The notion
ion of process is cent
centr
r al to the
the understan
derstandi
ding
ng of oper ati
ating syst
systems. Th
There are
quit
quite a few
few defin
definition
ions present
presenteded in the
the lit
liter ature,
ature, but
but no "perfect
"perfect" defin
definition
ion has
has yet
yet
a ppea
ppeared.
Definition
y A prog
progr am inin Execut
Execution
ion.
y An asyn
synchron
ronous activit
ivity.
y The 'an
'anim
imatated
ed sprit
sprit' of a
of a procedure in
in execut
execution
ion.
y The ent
entiity to whic
which h processors are assign
ssigned.
ed.
y The 'dispat
'dispatccha ble' un
unit.
and
and many
any more defin
definition
ions have
have given
iven. As we can see from a bove that therethere is no
universa
iversally agreed
agreed upon
upon defin
definition
ion, but
but the
the defin
definition
ion " P rogram
rogram in Execution"
Execution" seem to
be most
most frequent
frequently
ly used. An
And this
this is a con
concept
cept are will use inin the
the present
present study of
oper ati
ating syst
systems.
Now
Now that we agreed
agreed upon
upon the
the defin
definit ion
ion of process, the
the quest
question
ion is what is the
the relat
relatio
ion
n
betw
betwee
een
n process and
and prog
progr am. It
It is sa
same bea
beast with different
different name
name or wh
or wheen this
this bea
beast
is sleeping
sleeping (not execut
executing)
ng) it is called prog
progr am and
and whe
when it is execut
executing becomes
process. Well, to be very precise. Process is not thethe sa
same as prog
progr am. In
In the
the follow
following
discussion
discussion we point
point out
out some of th
of thee differen
difference betw
betwee
eenn process and
and prog
progr am. As we
have
have ment
mentio
ionned ea
earlier.
y Current
Current value of Prog
Progr am Count
Counterer (PC)
y Cont
Conteents
nts of th
of thee processors reg
regist
isters
y Value of th
of thee va
varia
ria bles
y The process stastacck (SP) whic
whichh typica
ypically conta
contaiins tempor ary data such
such as
subrout
subroutine pa
par amet
meter, ret
retur n address, and
and tempor ary va varia
ria bles.
y A data
data sect
section
ion that conta
contaiins globa
lobal va
varia
ria bles.
A process is the
the un
unit of w
of wor k i
k in a syst
system.
Process State
y Code for th
for thee prog
progr am.
y Prog
Progr am's stat
static
ic data
data..
y Prog
Progr am's dyna
dynamicmic data
data..
y Prog
Progr am's procedure ca call sta
stacck .
y Cont
Conteents
nts of g
of gener al purpose reg regist
isters.
y Cont
Conteents
nts of prog
progr am count
counterer (PC)
y Cont
Conteents
nts of prog
progr am stat
status
us word (PSW(PSW).
y Oper ati
ating Syst
Systems resource in in use.
y The current
current state
tate of the
the process i.e., whe
whether
ther it is rea
ready, runn
runniing,
ng, wai
waiting,
ng, or
whatever.
whatever.
y Unique ident
identific
ificat
atio
ionn of the
the process in in order to tr ack "whic
whichh is whic
whichh"
informat
formatioionn.
y A point
pointer
er tto pa
parent
rent process.
y Simila
Similarly, a point
pointer
er tto ch
child process (if it
it exist
exists).
y The priorit
priority of process (a (a par t of CPU sch
scheduling
eduling informat
formatio
ion
n).
y Point
Pointers
ers to locat
locatee memory of processes.
y A reg
regist
ister sa
save area
rea.
y The processor it it is runn
runniing on.
The PCB is a cer tai
tain store that allow
llows the
the oper ati
ating syst
systems to locat
locatee k ey
ey in
informat
formatio
ion
n
a bout
bout a process. Th
Thus, the
the PCB is thethe data struct
ructure that defin
defines a process to thethe
oper ati
ating syst
systems.
Threads
y Threa
reads
y Processes Vs Th Threareads
y Why
Why Th Threa
reads?
y User-Level Th Threareads
y K er
er nel-Level Th Threa
reads
y Advantag
Advantages es of ThThrea
reads over Mult
Multiple Processes
y Disa
Disadvantag
dvantages es of ThThrea
reads over MultMultiprocesses
y Applicat
Applicatio ionn that Ben
Benefit
efits from Th Threa
reads
y Applicat
Applicatio ionn that canno
annot ben
benefit
efit from Th
Threa
reads
y Resources used in in Threa
read creat
creatioionn and
and Process Creat
Creatio
ion
n
y Cont
Contexextt Switch
y Major
ajor St
Steps of ContContexextt Switching
y Act
Action
ion of K er er nel to Cont
Contex extt switch among
mong thre
threaads
y Act
Action
ion of k
of k er
er nel to Cont
Contexextt switch among
mong processes
Threads
Despit
Despite of th
of thee f act that a thre
threaad must
must execut
execute inin process, the
the process andand it
its associat
ssociated
ed
thre
threaads are different
different con concept
cept. Processes are used to group resources together ther and
and
thre
threaads are the
the enti
ntities sch
scheduled for execut
execution
ion on the
the CPU.
A thread is a single sequence stream within in a process. process . Beca
Because thre
threaads have
have some
of the
the proper ties of processes, they they are somet
sometimes ca called lightweight processes.
processes. In a
process, thre
threaads allow
llow mult
multiple execut
execution
ions of st strea
reams. In
In manyany respect
respect, thre
threaads are
popula
popular way
way to improve a pplicat pplicatioionn throu
through
gh par allelism. Th The CPU sw switches r a pidly
ba
back and
and for th th among
mong thethe thre
threaads giving
iving illusion
illusion that thethe thre
threaads are runnrunniing in
pa
par allel. Lik
Lik e a tr adit
ditiona
ionall process i.e., process with one thre threaad, a thre
threaad can
can be inin any
any
of sever al states
tates (Runn
(Runniing,
ng, Block
Block ed,ed, Rea
Ready or Terminat
Terminated).
ed). Ea
Each thre
threaad has
has its own
stac
tack . Sin
Since threthreaad will gener ally ca call different
different procedures and and thus
thus a different
different
execut
executionion hist
istory. ThThis is why
why thre
threaad needs it its own stac
tack . An oper atiating syst
system that
has
has thre
threaad f acilit
cility, the
the basic un unit of CPU ut utilizat
ilizatio
ion
n is a thre
threaad. A thre
threaad has
has or
con
consist
sists of a
of a prog
progr am count
counter
er (PC), a reg
regist
ister set
set, and
and a stac
tack spa
space. Th
Threa
reads are not
indepen
dependent
dent of one other
ther lik
lik e processes as a result
result thre
threaads shares
hares with other
ther thre
threaads
their
their code sect
section
ion, data sect
section
ion, OS resources also knoknown as tas
task , such
such as open
open files
and
and signa
signals.
ls.
Processes Vs Threads
As we ment
mentio
ion
ned ea
e arlier that
rlier that in many
any respect
respect thre
threaads oper ate
ate in
in the
the sa
s ame way
way as that
of processes. Some of th
of thee simila
similarit
rities and
and differen
differences are:
Similarities
y Lik
Lik e processes thre
threaads share
hare CPU and and only one thre threaad active (runn
(runniing)
ng) at a
time.
y Lik
Lik e processes, thre
threaads withi
thin a processes, thre
threaads withi
thin a processes execut
execute
sequent
sequentiially.
y Lik
Lik e processes, thre
threaad can
can creat
createe ch
children
ildren.
y And lik
lik e process, if on
one thre
threaad is block
bloc k ed,
ed, ano
another
ther th
thre
reaad can
can run
run.
Differences
y Unlik
lik e processes, thre
threaads are not indepen
dependent
dent of on
one ano
another.
ther.
y Unlik
lik e processes, all thre
threaads can
can access every address in
in the
the tas
task .
k .
y Unlik
lik e processes, thre
threaad are design
design to assist
ssist one other.
ther. Not
Note that processes
might
might or might
might not assist
ssist one ano
another
ther beca
because processes mamay orig
originate
nate from
different
different users.
Why Threads?
Follow
Follo wing are some rea
reason
sons why
why we use thre
threaads in
in design
designiing oper ati
ating syst
systems.
Threa
reads are ch
chea p in
in the
the sen
sense that
But
But this
this chea pn
pness does not come free - the
the bigg
bigges
estt dr aw
aw ba
back is that there
there is no
prot
protect
ection
ion betw
betwee
een
n thre
threaads.
User-Level Threads
User-level thre
threaads implement
implement in user-level libr aries, r ather
ather than
than via
via syst
systems ca
calls, so
thre
threaad switching does not need to call oper ati ating syst
system and
and to cause int
interrup
erruptt to the
the
k er
er nel. In
In f act, the
the k er
er nel kno
knows nothi
thing a bout
bout user-level thre
threaads and
and manages
anages them
them
as if th
if they
ey were sing
single-
le-th
thre
reaaded processes.
Advantages:
The most
most obvious advantag
dvantagee of th
of this
is techn
echnique
ique is that a user-level thre
threaads pa
package
kage can
can
be implement
implemented
ed on an Oper ati
ating Syst
System that does not suppor t thre
threaads. Some oth
other
er
advantag
dvantages
es are
y User-level thre
threaads does not require modificat
modificatio
ion
n to oper ati
ating syst
systems.
y Simple Representatio
Representat ionn:
Each thre
threaad is represent
represented
ed simply by a PC, reg regist
isters, sta
stacck and
and a sma
small
cont
control
rol block
block , all st
stored in
in the
the user process address spa
space.
y Simple Manageme
Manag ement
nt::
This simply meanme anss that creat
creatiing a thre
threaad, switching betw
betwee
eenn thre
threaads and
and
synchron
syn ronizat
izatio n betw
ion betweeeenn thre
threaads can all be don
done withou
thoutt interve
ntervent
ntio n of the
ion the
k er
er nel.
y Fast and
and Efficient::
Efficient
Threa
read sw
switching is not much
much more expen
expensive than a procedure ca call.
Disadvantages:
K ernel-Level
ernel-Level Threads
In this
this meth
method,
od, the
the k er
er nel kno
knows a bout
bout and
and manag
manageses the
the thre
threaads. No runt
runtime
ime syst
system is
needed in in this
this case. InInstead of thre
threaad ta ble in
in each process, thethe k er
er nel has
has a thre
threaad
ta ble that k eeps
eeps tr ack of all thre
threaads in thethe syst
system. InIn addit
ddition
ion, the
the k er
er nel also
maintai
ntains the
the tr adit
ditiona
ionall process ta ble to k eep
eep tr ack of processes. Oper ati
ating Syst
Systems
k er
er nel provides syst
system call to creat
createe and
and manage
anage thre
threaads.
The implementat
implementatio
ion
n of gener al struct
ructure of k er
er nel-level thre
threaad is
Advantages:
y Beca
Because k er
er nel has
has full kno
knowledg
ledge of a
of all thre
threaads, Sch
Scheduler mamay decide to give
more time to a process havi having
ng lar ge number of threthreaads than process havi
having
ng
sma
small number of th
of thre
reaads.
y K er
er nel-level thre
threaads are especia
especially good for a
for a pplicat
pplicatio
ion
ns that frequent
frequently
ly block
block .
Disadvantages:
y The k er
er nel-level thre
threaads are slow
slow and
and inefficient
efficient.. For in
instance,
tance, thre
threaads
oper atio
ationns are hundreds of t
of times slow
slower than
er than that of user-level thre
threaads.
y Sin
Since k er
er nel must
must manage
anage and
and sch
sc hedule thre
threaads as well as processes. ItIt require
a full thre
threaad cont
control
rol block
block (TCB)
(TCB) for eaeach thre
threaad to ma
maintai
ntain informat
formatio
ionn a bout
bout
thre
threaads. As a result
result there
there is sign
signific
ificant
ant over head andand increa
creased inin k er
er nel
complexit
complexity.
CPU/Process Scheduling
The assign
ssignme
ment
nt of physica
ysical processors to processes allow
llows processors to accomplish
ccomplish
wor k
k. Th
T he problem of det
de termin
ermining whe
when processors sh
should be assign
ssigned
ed and
and to whic
which
h
called processor sch
processes is ca scheduling
eduling or CPU sch
scheduling
eduling..
Whe
When more than one process is runa runa ble, the
the oper ati
ating syst
system must
must decide whic
whichh on e
first
first. The par t of the
the oper ati
ating syst
system con concer ned with this
this decision
decision is called the
the
sch
scheduler, and
and algorith
orithmm it
it uses is ca
called the
the sch
scheduling
eduling algorith
orithm.
m.
In this
this sect
section
ion we try to ans
answer follow
following quest
question
ion: What the
the sch
scheduler t
eduler try to achieve?
Many
any ob jec
jecttives must
must be con
considered in in the
the design
design of a sch
scheduling
eduling disciplin
discipline. In
pa
par ticula
icular, a sch
scheduler shshould con
consider f air ness, efficien
efficiency, respon
response time, tur narou
narounnd
time, throu
throughgh put
put, etc., Some of these
these goals depen
depends on thethe syst
system one is using
using for
exa
example batbatcch syst
system, int
inter
er active syst
system or rea
real-t
l-time syst
system, et
etc. but
but there
there are also
some goals that are desir a ble in in all syst
systems.
General Goals
Fairness
Fair ness is impor tant
tant under a
der all circumstan
circumstances.
ces. A sch
scheduler mak
mak eses sure that each
process gets its f air sharehare of the
the CPU and and no process cancan suffer in indefin
definite
post
post pon
ponement
ement.. Not
Note that giving
iving equiva
equivalent
lent or equa
equal time is not f air. Th
Think of safety
safety
control an
control and d payroll at
payroll at a nuclea
uclear plant
plant..
Policy Enforcement
The sch
sc heduler ha
eduler hass to mak
mak e sure that syst
system's policy is en
enforced. For exa
example, if
the
the loca
local policy is sasafet
fety the
then thethe safety control processesmus
processesmustt be a ble to run
run
whe
whenever th
ever they
ey want to, even
even if it
it mean
meanss dela
delay in
in payroll processes.
processes.
Efficiency
Sch
Scheduler sh
should k eep
eep the
the syst
system (or in
in par ticula
icular CPU) busy cent
cent percent
percent of th
of thee
time whe
when possible. If the
the CPU andand all the
the In put
put/Out
/Out put
put devices can
can be k ept
ept runn
runniing
all the
the time, more wor k g
k gets don
done per secon
second than if some compon
components
nts are idle.
Response Time
A sch
scheduler sh
should min
minimize the
the respon
response time for int
inter
er active user.
Turnaround
A sch
scheduler sh
should min
minimize the
the time bat
batcch users must
must wai
wait for an
for an out
out put
put.
Throughput
A sch
scheduler sh
should ma
maximize the
the number of jobs
jobs processed per un
unit time.
A litt
little
le thou
thought
ght will sh
show that some of th
of these
ese goals are cont
contr r adict
dictory. It
It can be shs hown
that any
any schscheduling
eduling algorith
orithm
m that f avors some claclass of j
of jobs
obs hur ts ano
another
ther cla
class of
jobs.
jobs. Th
The amount
mount of CPU time availa
ila ble is nifite, af ter all.
The Sch
Scheduling
eduling algorith
orithms
ms can be divided int
intoo two
two cate
ategories with respect
respect to ho w
they
they dea
deal with clock
clock iinterrup
nterruptts.
Nonpreemptive Scheduling
A sch
sc heduling
eduling disciplin
discipline is non preempt
preemptive if, on
once a process has
has been
been given
iven the
the CPU,
the
the CPU cann
cannoot be tak en away
away from that process.
Follow
Follo wing are some cha
char
r acterist
eristics of n
of non preempt
preemptive sch
scheduling
eduling
1. In non preempt
preemptive syst
system, sh shor t jobs
jobs are made to waiwait by long
longer
er j
jobs
obs but
but the
the
over all treat
reatme
ment
nt of a
of all processes is f air.
2. In non preempt
preemptive syst
system, respon
response times are more predicta predicta ble because
incoming
coming high priorit
priority jobs
jobs can
can not displa
displace wai
waiting j
ng jobs.
obs.
3. In non preempt
preemptive sch
scheduling
eduling,, a schschedula
edular execut
executes jobs
jobs in
in the
the follow
following twotwo
sit
situatio
ationns.
a. Whe
When a process sw switches from runnrunniing state
tate to the
the wai
waiting state.
tate.
b. Whe
When a process terminat
erminates.
es.
Preemptive Scheduling
A sch
sc heduling
eduling disciplin
discipline is preempt
preemptive if, on
once a process has
has been
been given
iven the
the CPU can
can
tak en away.
away.
The str ate
ategy of allow
llowing processes that are log
logica
ically runa
runa ble to be tempor arily
suspen
suspended is cacalled Preempt
Preemptive Sch
Scheduling
eduling and
and it is cont
contr
r ast to the
the "run
"run to
complet
completion
ion" meth
method.
od.
Deadlock
A set
set of process is in
in a dea
deadlock
dlock sstate
tate if ea
each process in in the
the set
set is wai
waiting for an
for an event
event
that can be ca
caused by ononly ano
another
ther process inin the
the set
set. In
In other
ther w
words, ea
each member of
the
the set
set of dea
deadlock
dlock processes is wai
waiting for a
for a resource that can be relea
released on
only by a
dea
deadlock
dloc k process. Non
None of the
the processes can can runrun, none of them
them can relea
release any
any
resources, and
and none of th
of them can be awak ened. It
em can It is impor tant
tant to note that the
the number
of processes andand the
the number and
and k ind of resources possessed and and request
requested are
unimpor tant.
tant.
The simplest
simplest exa example of dea deadlock
dlock is where
where process 1 has has been
been allocat
llocated
ed non-
share
hareaa ble resources A, say, a ta p drive, and and process 2 has has be allocat
llocated
ed non-sha
-shar r a ble
resource B, sasay, a print
printer.
er. Now
Now, if it
it tur ns out
out that process 1 needs resource B (print
(printer) er)
to proceed andand process 2 needs resource A (the the ta pe drive) to proceed and
and these
these are thethe
only two
two processes in in the
the syst
system, ea
each is block
block ed
ed the
the oth
other
er an
and
d all useful wor k
k in the
the
syst
system stops. Th This sit
situatio
ation
n ifs termed dea deadlock
dlock . The syst
system is inin dea
deadlock
dlock state
tate
beca
because ea each process holds a resource being being request
requested by thethe other
ther process neith
either er
process is willing
illing to relea
release the
the resource itit holds.
3. No-Preemptive Condition
Resources alrea
lready allocat
llocated
ed to a process cann
canno
ot be preempt
preempted.
Explanation: Resources canncanno ot be removed from the the processes are used to
complet
completion
ion or relea
released volunta
voluntarily
rily by the
the process holding
olding it.
As an exaample,
ex consider th
con thee tr affic deadloc
deadlock
k in thee
th following
follow fig
fi gure
Con
Consider ea
each sect
section
ion of th
of thee st
street
reet as a resource.
1. Mut
Mutual exclusion
exclusion concondit
dition
ion a pplies, sin
since only onone veh
vehicle can
can be on o n a sect
section
ion
of th
of thee st
street
reet at a time.
2. Hold-
Hold-anand-d-wa
waiit con
condit
dition
ion a pplies, sin
since each vehvehicle is occupying
occupying a sect section
ion of
the
the st
street
reet, and
and wai
waiting to move on on to the
the next
ext sect
section
ion of th
of thee st
street
reet.
3. No-preemp
No-preempttive con condit
dition
ion a pplies, sin
since a sect
section
ion of th
of thee st
street
reet that is a sect
section
ion of
the
the st
street
reet that is occupied by a veh vehicle cann
canno ot be tak en away
away from it it.
4. Circul
Circulaar wawaiit con
condit
dition
ion a pplies, since each veh vehicle is wai waiting on the the next
ext
veh
vehicle to move. That That is, ea
each veh
vehicle in
in the
the tr affic is wai
waiting for a
for a sect
section
ion of
street
reet held by thethe next
ext veh
vehicle in
in the
the tr affic.