You are on page 1of 14

BANSAL INSTITUTE OF SCIENCE

&TECHNOLOGY BHOPAL

Department of Computer Science Engineering

SESSION 2010-2011

SEMINAR/GROUP DISCUSSION

On

OPERATING SYSTEM

SUBMITTED TO SUBMITTEDBY:-
PROF. SHAHEEN AYYUB IND RAJEET G OUR

( H.O.D. C.S.E.DEPT.) (0112CS071110)


OPERATING SYSTEM

What is an Oper ati
ating Syst
System

The 1960¶s defin


definition
ion of  an oper ati
ating syst
system is ³th
³thee sof tware
tware that cont
controls
rols the
the
hard
hardwa
ware´.
re´. How
However, toda
oday, due to microcode we need a bettbetter
er defin
definition
ion. We see an
oper ati
ating syst
system as the
the prog
progr ams that mak e the
the hard
hardwa
ware
re usea
usea  ble. In brief, an
oper ati
ating syst
system is the
the set
set of prog
progr ams that cont
controls
rols a comput
computer. Some exa examples of 
oper ati
ating syst
systems are UNIX, Ma Mach, MS-DOS, MS-W
MS-Window dows, Windowdows/NT, Ch Chicag
icago,
o,
OS/2, Ma
MacOS, VMS, MVS, and and VM.

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

Objectives of Operating Systems

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.

y To hide details of hardware by creating abstraction


An a bst
 bstr action
ion is sof tware
tware that hides low
lower level deta
details
ils and
and provides a set
set of 
higher-level
gher-level fun function
ions. An oper ati
ating syst
system tr ansforms
ansforms thethe physica
ysical world of 
devices, in instruct
ruction
ions, memory, and and time int
intoo vir tual world that is thethe result
result of 
a bst
 bstr action
ions built
built by thethe oper ati
ating syst
system. Th There are sever al rea reason
sons for 
a bst
 bstr action
ion.
 First , the
the code needed to cont control
rol periph
peripher al devices is not stand tandardized.
Oper ati
ating syst
systems provide subrout
subroutines called device drivers that perform
oper atio
ation ns on beha behalflf of prog
progr ams for exa example, in in put
 put/out
/out put
 put oper atio
ationns.
Second , the the oper atiating syst
system introduces
ntroduces new fun function
ions as it a bst
 bstr acts the
the
hard
hardwaware.
re. For in instance,
tance, oper ati
ating syst
system int
i ntroduces
roduces the
the file a bst
 bstr action
ion so that
 prog
 progr ams do not have
have to dea
deal with disk 
disk s.
s.
Third , the
the oper atiating syst
system tr ansforms
ansforms thethe comput
computer  hard
hardwa
warere into
nto mult
multiple
vir tual comput
computers, ea each belong
belongiing to a different
different prog
progr am. EaEach prog
progr am that is
runn
runniing is ca c alled a process. EaEach process viewviews the
the hard
hardwa
warere throu
throughgh the
the len
lens
of  a bst
 bstr action
ion.
 Fourth,
 Fourth, the the oper atiating syst
system can enforce securit security throu
through gh a bst
 bstr action
ion.

y To allocate resources to processes (Manage resources)


An oper ati
ating syst
system cont
controls
rols how processes (the
the active age
agents)
nts) may
access resources (pa
(passive eent
ntiities).

y Provide a pleasant and effective user interface


The user intinter 
er acts with the
the oper ati
ating syst
systems throu
throughgh the
the user int
interf 
erf ace and
and
usually int
usua interes
erestted in the
the ³look 
³look  and
and feel´ of  the the oper ati
ating syst
system. ThThe most
most
impor tant
tant compon
components nts of  the
the user int
interf 
erf ace are thethe comman
command d interpre
nterpretter, the
the
file syst
system, onon-lin
-line help, and
and a pplicat
 pplicatio
ionn inte
ntegr atio
ationn. Th
T he recent
recent tren
rend has
has been
been
toward
ward increa
creasing
singly
ly inte
ntegr ated
ated gr a ph
 phica
ical user intinterf 
erf aces that encompa
compass thethe
activit
ivities of mult
multiple processes on on networ 
twor k 
ks  of comput
computers.

One can view view Oper ati ating Syst


Systems from two two point
pointss of viewvie ws: Resource
manager andand Extended machines. Form Resource manag manager
er point
point of view
view Oper ati
ating
Syst
Systems manag
managee the
the different
different par ts of  the
the syst
system efficient
efficiently
ly and
and from ext
extended
machines point
point of view
view Oper ati ating Syst
Systems provide a vir tual machine to users that is
more conconven
venient
ient to use. Th The struct
ructur ally Oper ati
ating Syst
Systems cancan be design
design as a
mon
monolith
olithic
ic syst
system, a hier archrchy of la
layers, a vir tual machine syst
system, an exok 
exok er 
er nel, or 
using
using the
the client
client-server
-server model. Th The ba
basic con
concept
cepts of Oper ati
ating Syst
Systems are processes,
memory manag
managemeement
nt,, I/O manag
managemeement
nt,, the
the file syst
systems, and
and securit
security.
Definition of Process

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

The term "process" was


was first
first used by the
the design
designers
ers of th
of  thee MULTICS in in 1960's. Sin
Since
the
then, the
the term process, used somewhat
somewhat interc
nterchang
hangeea bly with 'tas
task ' or  job'.
 'job'. Th
The process
has
has been
been given
iven many
any defin
definition
ions for in
instance
tance

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.

Process is not the


the sa
same as prog
progr am. A process is more than a prog
progr am code. A process
is an 'active' ent
entiity as oppose to prog
progr am whic
whichh con
consider t
sider to be a 'pa
'passive' ent
entiity. As we
all kno
know that a prog
progr am is an algorith
orithm
m expressed inin some suita
suita ble notatio
tationn, (e.g
(e.g.,
 prog
 progr amming
mming langu
anguage).
age). Being
Being a passive, a prog
progr am is on
only a par t of process. Process,
on the
the oth
other 
er han
hand,
d, in
includes:

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.

In Process model, all sof tware


tware on thethe comput
computer is or ganized
ganized intinto
o a number of 
sequent
sequentiial processes. A process in includes PC, regregist
isters, and
and varia
ria  bles. Con
Concept
ceptually,
each process has
has its own vir tual CPU. In I n rea
realit
lity, the
the CPU sw switches back  and
and for th
th
among
mong processes. (Th
(The r a pid sw
s witching back an
k  and
d for th
th is ca
called mult
multiprog
iprogr amming
mming).
).

Process State

The process stat


statee con
consist
sist of everyth
everythiing necessa
ecessary to resume the the process execut
execution
ion if it
it
is someh
somehow put
put aside tempor arily. Th
The process stat
statee con
consist
sists of at
of at lea
least follow
following:
ng:

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.

Process Control Block 

A process inin an oper ati


ating syst
system is represent
represented
ed by a data struct
ructure kno
known as a process
cont
control
rol block 
block  (PCB) or process descript
descriptor. Th
The PCB conta
contaiins impor tant
tant informat
formatio
ion
n
a bout
 bout the
the specific process in
including
cluding

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.

1. A process with mult


multiple thre
threaads mak 
mak e a great
reat server for exa
example print
printer
er server.
Because thre
2. Beca threaads can share
hare common
common data,ata, they
they do not need to use int
interprocess
erprocess
commun
communicat
icatio
ionn.
3. Beca
Because of th
of thee very nature,
nature, thre
threaads can
can tak e advantag
dvantagee of mult
multiprocessors.

Threa
reads are ch
chea p in
in the
the sen
sense that

1. They ononly need a stac


tack  and
and st
s tor age
age for reg
regist
isters therefore,
therefore, thre
threaads are ch
c hea p to
creat
create.
e.
2. Threa
reads use very litt little
le resources of  an oper ati
ating syst
system in whic
which h they
they are
wor k 
ki  ng.
ng. That
T hat is, thre
threaads do not need new address spa space, globa
lobal data
d ata,, prog
progr am
code or oper ati
ating syst
system resources.
3. Cont
Contex
extt switching are f ast whewhen wor k 
ki  ng with thre
threaads. Th
The rea
reason
son is that we
only have
have to sasave and/or
and/or rest
restore PC, SP and
and reg
regist
isters.

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:

y There is a lack  of coordinat


coordinatio
ion
n betw
betweeeenn thre
threaads and
and oper ati
ating syst
system k er 
er nel.
Therefore, process as wholewhole gets on
one time slice irrespect
irrespect of wh
of wheether
ther process has
has
one thre
threaad or 1000 thre
threaads withi
thin. It
It is up to ea
each thre
threaad to relin
relinquish
quish cont
control
rol to
other 
ther th
thre
reaads.
y User-level threthreaads requires non-block 
-block ing syst
systems ca call i.e., a mult
multithre
threaaded
k er 
er nel. Oth
Other 
er wise, ent
entire
ire process will block 
block ed
ed in the
the k er 
er nel, even
even if  there
there are
runa
runa ble thre
threaads lef t in the
the processes. For exa
example, if on
one thre
threaad causes a page
age
f ault
ult, the
the process block 
block s.
s.

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.

Goals of Scheduling (objectives)

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.

Preemptive VsNonpreemptive Scheduling

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 resources mamay be eith


either
er physica
ysical or log
logica
ical. Exa
Examples of ph
physica
ysical resources are
Print
Printers,
ers, Ta
Ta  pe Drivers, Memory Space, and and CPU  Cycles. Exa
Examples of log lo gica
ical
resources are Files, Sema
Sema ph
 phores, and
and Mon
Monitors.

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.

Preemptable and Nonpreemptable Resources

Resources come in in two


two fla
flavors: preempta
preempta ble and
and non preempta
 preempta  ble. A preempta ble
resource is onone that can be tak en away
away from the
the process with no ill effect
effects. Memory is
an exa
example of aof  a preempta
preempta ble resource. On
On the
the oth
other 
er han
hand,d, a non preempta
 preempta ble resource
is one that cannoannot be tak en away
away from process (w (withou
thoutt causing
using ill effect
effect). For 
exa
example, CD resources are not preempta preempta ble at an arbit rbitr ary moment
moment..
Rea
Reallocat
llocatiing resources cancan resolve dea
deadlock 
dlock s that involve preempta
preempta  ble resources.
Dea
Deadlock 
dloc k s that involve non preempta
 preempta ble resources are difficult
difficult to dea
deal with.
th.

Necessary and Sufficient Deadlock Conditions


Coffman
Coffman (1971) ident
identified
ified four (4) conditions that must
must hold simultan
simultaneously
eously for th
for there
ere
to be a dea
deadlock 
dloc k .

1. Mutual Exclusion Condition


The resources in
involved are non-sha
-share
reaa ble.
Explanation: At lealeast one resource (th
(thre
reaad) must
must be held in
in a non-sha
-share
reaa  ble mode,
that is, on
only on
one process at a time cla
claims exclusive cont
control
rol of th
of  thee resource. If an
If  ano
other 
ther 
  process requests that resource, the
the request
requesting process must
must be dela delayed untuntil
il the
the
resource has
has been
been relea
released.

2. Hold and Wait Condition


Request
Requesting process hold alrea lready, resources while
while wai
waiting for request
requested
resources.
Explanation: There must
must exist
exist a process that is holding
olding a resource alrea
lready allocat
llocated
ed
to it while
while wai
waiting for  addit
dditiona
ionall resource that are current
currently
ly being
being held by oth
other 
er 
 processes.

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.

4. Circular Wait Condition


The processes in in the
the syst
system form a circula
circular list
list or cha
c haiin where
where eaeach process in
in
the
the list
list is wai
waiting for a
for a resource held by the
the next
ext process in in the
the list
list.

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.

The simple rule to avoid tr affic dea deadlock 


dloc k  is that a veh
vehicle sh
should ononly enter 
nter  an
intersec
ntersecttion
ion if it
it is assured that it will not have
have to st
stop in
inside the
the int
intersec
ersecttion
ion.

It is not possible to have


have a dea
deadlock 
dlock  involving
volving only on
o ne sing
single
le process. Th
The dea
de adlock 
dloc k 
involves a circula
circular ³hold-an
old-and-
d-wa
waiit´ con
condit
dition
ion betw
betwee
een
n two
two or more processes, so
³on
³one´ process canncanno
ot hold a resource, yet
yet be wai
waiting for  ano
another
ther resource that it is
holding
olding.. In addit
ddition
ion, dea
deadlock 
dlock  is not possible betw
betwee
eenn two
two thre
threaads in a process,
 beca
 because itit is the
the process that holds resources, not the
the thre
threaad that is, ea
each thre
threaad has
has
access to the
the resources held by the
the process.

You might also like