Project Report of Operating System

Share Embed Donate


Short Description

OPERATING SYSTEM report...

Description

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 bett better 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, Window dows/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 different differentiiate ate k er  er nel services, libr ary services, and and a pplicat  pplicatio ion 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 which h are link  link ed ed together  ther  with libr aries that perform stan stand dard 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 the the k er  er nel, a cont control rol prog progr am that fun function ions in i n privileged state (an execut execution ion cont contex extt that allow llows all hard hardwa ware re instruct ruction ions to be execut executed), rea reacting to interrup nterruptts from ext exter nal nal devices and and 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. It It creat creates es and and terminat erminates es processes and and respon responds to their their request request for service. Oper ati ating Syst Systems are resource manag managers. ers. Th The ma main resource is comput computer ha er hard rdwa ware re in in the the form of processors, st age, in put n devices, and and stor age,  put/out /out put  put devices, commun communicat icatio ion data. ata. Some of  the the oper ati ating syst system fun function ions are: implement implementiing the the user int interf  erf ace, shari haring ng hard hardwa ware re among mong users, allow llowing users to share hare data among mong themselves, themselves,  prevent  preventiing users from int interferi erfering ng 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 ation ns, or ganizi ganizing ng data for secure and and r a pid access, and and handli handling ng networ  twor k commu k  commun nicat ns. icatio 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 in in low low privileg privilege and and the oper ati ating syst gh-privileg ge stat  providing  providing service ca calls that invok  vok e the system k er  er nel in in high-privile 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 the the physica ysical world of  devices, in instruct ruction ions, memory, and and time int into o vir tual world that is the the result result of  a bst  bstr action ions built built by the the 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 behalf lf of prog progr ams for exa example, in in put  put/out /out put  put oper atio ation ns. Second , the the oper ati ating syst system introduces ntroduces new fun function ions as it a bst  bstr acts the the hard hardwa ware. 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 ati ating syst system tr ansforms ansforms the the comput computer  hard hardwa ware re into nto mult multiple vir tual comput computers, ea each belong belongiing to a different different prog progr am. Ea Each prog progr am that is runn runniing is ca c alled a process. Ea Each process view views the the hard hardwa ware re throu through gh the the len lens of  a bst  bstr action ion.  Fourth,  Fourth, the the oper ati ating syst system can enforce securit security throu through gh a bst  bstr action ion. y

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). Provide a pleasant and effective user interface the oper ati ating syst through gh the the user int and The user int inter  er acts with the systems throu interf  erf ace and the ³look  and feel´ of  the the oper ati ating syst usua usually int interes erestted in the ³look  and system. Th The most most impor tant tant compon components nts of  the the user int interf  erf ace are the the comman command d interpre nterpretter, the the file syst system, on on-lin -line help, and and a pplicat  pplicatio ion n inte ntegr atio ation n. 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 int interf  erf aces that encompa compass the the 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 view vie ws: Resource manager and and 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 con conven venient ient to use. Th The struct ructur ally Oper ati ating Syst Systems can can be design design as a mon monolith olithic ic syst system, a hier arch rchy 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 manageme ement nt,, I/O manag manageme ement 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 presented ed 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

y

y

y

y

A prog progr am in in Execut Execution ion. An asyn synchron ronous activit ivity. The 'an 'anim imat ated ed sprit sprit' of a of a procedure in in execut execution ion. The ent entiity to whic which h processors are assign ssigned. ed. 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 there there 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 in in 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 the the 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 een n process and and prog progr am. As we have have ment mentio ion ned 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 which h 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 in in some suita suita ble notatio tation n, (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

y

y

Current Current value of Prog Progr am Count Counter er (PC) Cont Conteents nts of th of thee processors reg regist isters Value of th of thee va varia ria bles

y

y

The process sta stacck  (SP) whic which h 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. 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 the the comput computer is or ganized ganized int into o a number of  sequent sequentiial processes. A process in includes PC, reg regist 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

y

y

y

y

y

y

y

Code for th for thee prog progr am. Prog Progr am's stat static ic data data.. Prog Progr am's dyna dynamic mic data data.. Prog Progr am's procedure ca call sta stacck . Cont Conteents nts of g of gener al purpose reg regist isters. Cont Conteents nts of prog progr am count counter er (PC) Cont Conteents nts of prog progr am stat status us word (PSW (PSW). Oper ati ating Syst Systems resource in in use.

Process Control Block 

A process in in 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

y

y

y

y

y

y

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. Unique ident identific ificat atio ion n of  the the process in in order  to tr ack  "whic which h is whic which h" informat formatio ion n. A point pointer  er tto pa parent rent process. Simila Similarly, a point pointer  er tto ch child process (if it it exist exists). The priorit priority of process (a (a par t of CPU sch scheduling eduling informat formatio ion n). Point Pointers ers to locat locatee memory of processes. A reg regist ister sa save area rea. 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 the the data struct ructure that defin defines a process to the the oper ati ating syst systems.

Threads

y

y

y

y

y

y

y

y

y

y

y

y

y

y

Threa reads Processes Vs Th Threa reads Why Why Th Threa reads? User-Level Th Threa reads K er  er nel-Level Th Threa reads Advantag Advantages es of Th Threa reads over Mult Multiple Processes Disa Disadvantag dvantages es of Th Threa reads over Mult Multiprocesses Applicat Applicatio ion n that Ben Benefit efits from Th Threa reads Applicat Applicatio ion n that canno annot ben benefit efit from Th Threa reads Resources used in in Threa read creat creatio ion n and and Process Creat Creatio ion n Cont Contex extt Switch Major ajor St Steps of Cont Contex extt Switching Act Action ion of K er  er nel to Cont Contex extt switch among mong thre threaads Act Action ion of k  of k er  er nel to Cont Contex extt switch among mong processes

Threads

Despit Despite of th of  thee f act that a thre threaad must must execut execute in in process, the the process and and 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 many any respect respect, thre threaads are  popula  popular  way way to improve a pplicat  pplicatio ion n throu through gh par allelism. Th The CPU sw switches r a pidly  ba  back  and and for th th among mong the the thre threaads giving iving illusion illusion that the the thre threaads are runn runniing 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 in in 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 thre threaad will gener ally ca call different different procedures and and thus thus a different different execut execution ion hist istory. Th This is why why thre threaad needs it its own stac tack . An oper ati ating 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 kno known 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

y

y

y

Lik  Lik e processes thre threaads share hare CPU and and only one thre threaad active (runn (runniing) ng) at a time. Lik  Lik e processes, thre threaads withi thin a processes, thre threaads withi thin a processes execut execute sequent sequentiially. Lik  Lik e processes, thre threaad can can creat createe ch children ildren. 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

y

y

Why

Unlik  lik e processes, thre threaads are not indepen dependent dent of on one ano another. ther. Unlik  lik e processes, all thre threaads can can access every address in in the the tas task . k  . 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 ma may orig originate nate from different different users.

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. threaads can share hare common ata, they they do not need to use int 2. Beca Because thre common data, interprocess erprocess commun communicat icatio ion n. 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 on only 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 whe when wor k  ki  ng with thre threaads. Th The rea reason son is that we only have have to sa save 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 singlele-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

y

y

y

User-level thre threaads does not require modificat modificatio ion n to oper ati ating syst systems. Simple Representatio Representat ion n: 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. Simple Manageme Manag ement nt:: This simply mean me anss that creat creatiing a thre threaad, switching betw betwee een n thre threaads and and n betw n thre threaads can all be don thoutt interve ntervent ntio n of  the the syn synchron ronizat izatio ion betwee een done withou ion k er  er nel. Fast and and Efficient:: Efficient Threa read sw switching is not much much more expen expensive than a procedure ca call.

Disadvantages: y

y

There is a lack  of coordinat coordinatio ion n betw betwee een n thre threaads and and oper ati ating syst system k er  er nel. Therefore, process as whole whole 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. User-level thre threaads 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 manages es the the thre threaads. No runt runtime ime syst system is needed in this case. In threaad ta  ble in the k er  has a thre threaad in this Instead of  thre in each process, the er nel has ta ble that k eeps eeps tr ack  of  all thre threaads in the the syst system. In In 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

y

Beca Because k er  er nel has has full kno knowledg ledge of a of  all thre threaads, Sch Scheduler ma may decide to give more time to a process havi having ng lar ge number of  thre threaads than process havi having ng sma small number of th of thre reaads. er nel-level thre threaads are especia especially good for a for a pplicat  pplicatio ion ns that frequent frequently ly block  block . K er 

Disadvantages: y

y

The k er  er nel-level thre threaads are slow slow and and inefficient efficient.. For in instance, tance, thre threaads oper atio ation ns are hundreds of t of times slow slower than er than that of user-level thre threaads. Sin Since k er  er nel must must manage anage and and sch sc hedule thre threaads as well as processes. It It require a full thre threaad cont control rol block  block (TCB) (TCB) for ea each thre threaad to ma maintai ntain informat formatio ion n a bout  bout thre threaads. As a result result there there is sign signific ificant ant over head and and increa creased in in 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  processes is ca called processor sch 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 which h 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 orithm m 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 sh should con consider f air ness, efficien efficiency, respon response time, tur narou naroun nd time, throu through gh put  put, etc., Some of  these these goals depen depends on the the syst system one is using using for  exa example bat batcch 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 es es sure that each  process gets its f air share hare of  the the CPU and and no process can can 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 then the the  safety control processesmus local policy is sa safet fety the 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 and and 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 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.

Time

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 sh s hown that any any sch scheduling eduling algorith orithm m that f avors some cla class 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 into o 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 canno ot 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 wai wait 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 sch schedula edular execut executes  jobs  jobs in in the the follow following two two sit situatio ation ns. a. Whe When a process sw switches from runn runniing 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. ategy of  allow The str ate llowing processes that are log logica ically runa runa ble to be tempor arily suspen suspended is ca called 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 on only ano another ther process in in 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 run run, none of  them them can relea release any any and none of th tant to note that the the number  resources, and of  them em can can be awak ened. It It is impor tant of processes and and the the number  and and k ind of resources possessed and and request requested are unimpor tant. tant. The resources ma may 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 nonshare 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, sa say, a print printer. er. Now Now, if it it tur ns out out that process 1 needs resource  B (print (printer) er) to proceed and and process 2 needs resource  A (the the ta pe drive) to proceed and and these these are the the 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 in in dea deadlock  dlock  state tate  beca  because ea each process holds a resource being being request requested by the the other ther process neith either  er   process is willing illing to relea release the the resource it it 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 on one that can be tak en away away from the the process with no ill effect effects. Memory is an exa example of a of  a preempta preempta ble resource. On On the the oth other  er han hand, d, a non preempta  preempta ble resource is one that canno annot 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 can can 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 lea least 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 unt until 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 cann canno 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 ea each 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 dea dlock  k  in

Con Consider ea each sect section ion of th of thee st street reet as a resource.

thee th

following follow

fig fi gure

1. Mut Mutual exclusion exclusion con condit dition ion a pplies, sin since only on one veh vehicle can can be on o n a sect section ion of th of thee st street reet at a time. 2. HoldHold-an andd-wa waiit con condit dition ion a  pplies, sin since each veh vehicle 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  wa waiit 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 the the 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 on only 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-andd-wa waiit´ con condit dition ion betw betwee een n two two or more processes, so ³on ³one´ process cann canno 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 een n two two thre threaads in a process,  beca  because it it 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.

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF