SlideShare a Scribd company logo
Deadlock
Prevention and Avoidance
Deadlock in real life..
Deadlock is:
 A set of blocked processes each holding a resource and
waiting to acquire a resource held by another process in the
set.
There are three policy conditions that must hold for a deadlock to be
possible (the “necessary conditions”):
1. Mutual Exclusion
2. Hold-and-Wait
3. No Preemption
4. Circular Wait
The (4) Conditions for Deadlock
 Deadlock occurs if and only if the circular
wait condition is unresolvable
 The circular wait condition is unresolvable
if the first 3 policy conditions hold
 So the 4 conditions taken together constitute
necessary and sufficient conditions for
deadlock
The Conditions for Deadlock
Approaches to handle deadlock
 Deadlock Prevention
 Deadlock Avoidance
 Deadlock Detection and
Recovery
1. A process acquires all the needed resources
simultaneously before it begins its
execution, therefore breaking the hold and
wait condition.
Deadlock Prevention
E.g. In the dining philosophers’ problem, each philosopher is required to pick up both
forks at the same time. If he fails, he has to release the fork(s) (if any) he has
acquired.
2. All resources are assigned unique numbers. A
process may request a resource with a unique
number I only if it is not holding a resource with a
number less than or equal to I and therefore
breaking the circular wait condition.
E.g. In the dining philosophers problem, each philosopher is required to pick a
fork that has a larger id than the one he currently holds. That is, philosopher P5
needs to pick up fork F5 and then F1; the other philosopher Pi should pick up fork
Fi followed by Fi-1.
3. Each process is assigned a unique priority number.
The priority numbers decide whether process Pi
should wait for process Pj and therefore break the
non-preemption condition.
4. Practically it is impossible to provide a method to
break the mutual exclusion condition since most
resources are intrinsically non-sharable, e.g., two
philosophers cannot use the same fork at the same
time.
Deadlock Avoidance
Avoid actions that may lead to deadlock.
Think of it as a safe state moving from one state to another as
instruction is executed.
We can avoid the situation of deadlock by :
1.Safe state
2. Bankers Algorithm
3.Resource allocation graph
Safe state
" ■ System is in safe state if there exists a safe sequence of all
processes."
When a process requests an available resource, system must decide if
immediate allocation leaves the system in a safe state.
■ Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be
satisfied by currently available resources + resources held by all the Pj, with j<I."
● If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.“
● When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and
terminate. "
● When Pi terminates, Pi+1 can obtain its needed resources, and so on. "
A resource allocation graph is generally used to avoid deadlocks. If there are no cycles in
the resource allocation graph, then there are no deadlocks. If there are cycles, there may
be a deadlock. If there is only one instance of every resource, then a cycle implies a
deadlock.
Consider the image with calm edges as below:
If R2 is allocated to p2 and if P1 request for R2, there will be a deadlock.
Resource allocation graph
Example: The banker knows that all 4 clients need 22
units together, but he has only total 10 units
Banker’s Algorithm:
ADAM 0 6
EVE 0 5
JOE 0 4
MARY 0 7
ADAM 1 6
EVE 1 5
JOE 2 4
MARY 4 7
ADAM 1 6
EVE 2 5
JOE 2 4
MARY 4 7
The Banker algorithm, sometimes referred to as the detection algorithm, is a resource
allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for
safety by simulating the allocation of predetermined maximum possible amounts of all
resources, and then makes an "s-state" check to test for possible deadlock conditions
for all other pending activities, before deciding whether allocation should be allowed to
continue.
Data Structures for the Banker’s
Algorithm
• Available: Vector of length m.
If available [j] = k, there are k instances of resource type Rj available.
• Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most
k instances of resource type Rj.
• Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently
allocated k instances of Rj.
• Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances
of Rj to complete its task.
Need [i,j] = Max[i,j] – Allocation [i,j].
Let n = number of processes, and m = number of resources types.
Safety Algorithm
1. Let Work and Finish be vectors of length m and n,
respectively. Initialize: Work = Available Finish [i] =
false for i = 1,2, …, n.
2. Find and i such that both: (a) Finish [i] = false (b)
Needi Work If no such i exists, go to step 4.
3. Work = Work + Allocationi Finish[i] = true go to step 2
4. If Finish [i] == true for all i, then the system is in a safe
state.
Requesti = request vector for process Pi.
Requesti [ j ] == k means that process Pi wants k instances of resource type Rj.
1. If Requesti Needi go to step 2. Otherwise, raise error condition, since process
has exceeded its maximum claim
2. If Requesti Available, go to step 3. Otherwise Pi must wait, since resources are
not available.
3. Test to allocate requested resources to Pi by modifying the state as follows:
Available = Available - Requesti;
Allocationi = Allocationi + Requesti;
Needi = Needi – Requesti;
• If safe == the resources are allocated to Pi.
• If unsafe == Pi must wait, and the old resource-allocation state is restored
Resource-Request Algorithm for Process Pi
Deadlock avoidance and prevention .. computer networking

More Related Content

What's hot

Bankers
BankersBankers
Dead Lock
Dead LockDead Lock
Dead Lock
Ramasubbu .P
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
MsAnita2
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
Sonali Chauhan
 
BANKER'S ALGORITHM
BANKER'S ALGORITHMBANKER'S ALGORITHM
BANKER'S ALGORITHM
Muhammad Baqar Kazmi
 
Thread
ThreadThread
Thread
Mohd Arif
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
vinay arora
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!
Ashish K
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
Ali Haider
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
prachi mewara
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
DHIVYADEVAKI
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
Pratik Tambekar
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
Sweetestangel Kochar
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
Saranya Natarajan
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
wahab13
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
ShushrutGupta
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
Venkata Sreeram
 
Concurrency
ConcurrencyConcurrency
Concurrency
rizwanaabassi
 
Distributed transactions
Distributed transactionsDistributed transactions
Distributed transactions
Aritra Das
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
koolkampus
 

What's hot (20)

Bankers
BankersBankers
Bankers
 
Dead Lock
Dead LockDead Lock
Dead Lock
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
 
Operating System Deadlock Galvin
Operating System  Deadlock GalvinOperating System  Deadlock Galvin
Operating System Deadlock Galvin
 
BANKER'S ALGORITHM
BANKER'S ALGORITHMBANKER'S ALGORITHM
BANKER'S ALGORITHM
 
Thread
ThreadThread
Thread
 
OS - Deadlock
OS - DeadlockOS - Deadlock
OS - Deadlock
 
Concurrency control!
Concurrency control!Concurrency control!
Concurrency control!
 
Dead Lock in operating system
Dead Lock in operating systemDead Lock in operating system
Dead Lock in operating system
 
Deadlock Prevention
Deadlock PreventionDeadlock Prevention
Deadlock Prevention
 
Deadlock Detection in Distributed Systems
Deadlock Detection in Distributed SystemsDeadlock Detection in Distributed Systems
Deadlock Detection in Distributed Systems
 
Distributed Transaction
Distributed TransactionDistributed Transaction
Distributed Transaction
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
concurrency-control
concurrency-controlconcurrency-control
concurrency-control
 
deadlock avoidance
deadlock avoidancedeadlock avoidance
deadlock avoidance
 
Concurrency control PPT
Concurrency control PPTConcurrency control PPT
Concurrency control PPT
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Distributed transactions
Distributed transactionsDistributed transactions
Distributed transactions
 
16. Concurrency Control in DBMS
16. Concurrency Control in DBMS16. Concurrency Control in DBMS
16. Concurrency Control in DBMS
 

Similar to Deadlock avoidance and prevention .. computer networking

Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
Nivedita Kasturi
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
sangrampatil81
 
OS_Ch8
OS_Ch8OS_Ch8
OSCh8
OSCh8OSCh8
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
ImranKhan880955
 
Deadlock
DeadlockDeadlock
Deadlock
Mahershi ACT
 
Ice
IceIce
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
MogilicharlaPavanKal
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
madhuributani
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
GRajendra
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
KAnurag2
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
amadayshwan
 
Section07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.pptSection07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.ppt
jbri1395
 
deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
Monirul Islam
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
C.U
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
ssusere16bd9
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
Unknown664473
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
Nusaike Mufthie
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
shreesha16
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
GovindJha93
 

Similar to Deadlock avoidance and prevention .. computer networking (20)

Gp1242 007 oer ppt
Gp1242 007 oer pptGp1242 007 oer ppt
Gp1242 007 oer ppt
 
Methods for handling deadlock
Methods for handling deadlockMethods for handling deadlock
Methods for handling deadlock
 
OS_Ch8
OS_Ch8OS_Ch8
OS_Ch8
 
OSCh8
OSCh8OSCh8
OSCh8
 
CH07.pdf
CH07.pdfCH07.pdf
CH07.pdf
 
Deadlock
DeadlockDeadlock
Deadlock
 
Ice
IceIce
Ice
 
Section07-Deadlocks.pdf
Section07-Deadlocks.pdfSection07-Deadlocks.pdf
Section07-Deadlocks.pdf
 
Ch 4 deadlock
Ch 4 deadlockCh 4 deadlock
Ch 4 deadlock
 
9 deadlock
9 deadlock9 deadlock
9 deadlock
 
Module-2Deadlock.ppt
Module-2Deadlock.pptModule-2Deadlock.ppt
Module-2Deadlock.ppt
 
Section07-Deadlocks (1).ppt
Section07-Deadlocks (1).pptSection07-Deadlocks (1).ppt
Section07-Deadlocks (1).ppt
 
Section07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.pptSection07-Deadlocks_operating_system.ppt
Section07-Deadlocks_operating_system.ppt
 
deadlock in OS.pptx
deadlock in OS.pptxdeadlock in OS.pptx
deadlock in OS.pptx
 
Ch8 OS
Ch8 OSCh8 OS
Ch8 OS
 
OSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptxOSLec14&15(Deadlocksinopratingsystem).pptx
OSLec14&15(Deadlocksinopratingsystem).pptx
 
14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt14th November - Deadlock Prevention, Avoidance.ppt
14th November - Deadlock Prevention, Avoidance.ppt
 
Deadlock (1).ppt
Deadlock (1).pptDeadlock (1).ppt
Deadlock (1).ppt
 
Module 3 Deadlocks.pptx
Module 3 Deadlocks.pptxModule 3 Deadlocks.pptx
Module 3 Deadlocks.pptx
 
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptxOS - Unit 3 Deadlock (Bankers Algorithm).pptx
OS - Unit 3 Deadlock (Bankers Algorithm).pptx
 

Recently uploaded

Best Immigration Consultants in Amritsar- SAGA Studies
Best Immigration Consultants in Amritsar- SAGA StudiesBest Immigration Consultants in Amritsar- SAGA Studies
Best Immigration Consultants in Amritsar- SAGA Studies
SAGA Studies
 
Greeting powerpoint slide for kids( 4-6 years old)
Greeting powerpoint slide for kids( 4-6 years old)Greeting powerpoint slide for kids( 4-6 years old)
Greeting powerpoint slide for kids( 4-6 years old)
lenguyenthaotrang663
 
DOJO Training room | Training DOJO PPT
DOJO Training room | Training DOJO   PPTDOJO Training room | Training DOJO   PPT
DOJO Training room | Training DOJO PPT
Himanshu
 
Generate Revenue with Contact Center Business Model Strategy
Generate Revenue with Contact Center Business Model StrategyGenerate Revenue with Contact Center Business Model Strategy
Generate Revenue with Contact Center Business Model Strategy
RNayak3
 
METS Lab SASO Certificate Services in Dubai.pdf
METS Lab SASO Certificate Services in Dubai.pdfMETS Lab SASO Certificate Services in Dubai.pdf
METS Lab SASO Certificate Services in Dubai.pdf
sandeepmetsuae
 
Understanding Love Compatibility or Synastry: Why It Matters
Understanding Love Compatibility or Synastry: Why It MattersUnderstanding Love Compatibility or Synastry: Why It Matters
Understanding Love Compatibility or Synastry: Why It Matters
AstroForYou
 
Discover How Long Do Aluminum Gutters Last?
Discover How Long Do Aluminum Gutters Last?Discover How Long Do Aluminum Gutters Last?
Discover How Long Do Aluminum Gutters Last?
SteveRiddle8
 
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
Traditional Healer, Love Spells Caster and Money Spells That Work Fast
 
The study compares AMUSE's FDM and MJF 3D printing technologies.pptx
The study compares AMUSE's FDM and MJF 3D printing technologies.pptxThe study compares AMUSE's FDM and MJF 3D printing technologies.pptx
The study compares AMUSE's FDM and MJF 3D printing technologies.pptx
Amuse
 
Siddhivinayak temple timings Houston, TX
Siddhivinayak temple timings Houston, TXSiddhivinayak temple timings Houston, TX
Siddhivinayak temple timings Houston, TX
gaurisiddhivinayakte
 
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdfThe best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
tonytkelly6
 
Bridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
Bridging the Language Gap The Power of Simultaneous Interpretation in RwandaBridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
Bridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
Kasuku Translation Ltd
 
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
Summerland Environmental
 
x ray baggage scanner manufacturers in India
x ray baggage scanner manufacturers in Indiax ray baggage scanner manufacturers in India
x ray baggage scanner manufacturers in India
Gujar Industries India Pvt. Ltd
 
Emmanuel Katto Uganda - A Philanthropist
Emmanuel Katto Uganda - A PhilanthropistEmmanuel Katto Uganda - A Philanthropist
Emmanuel Katto Uganda - A Philanthropist
Marina Costa
 
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptxTop Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
Merchantech - Payment Processing Services
 
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptxBiomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
ECOSTAN Biofuel Pvt Ltd
 
The Fraud Examiner’s Report – What the Certified Fraud Examiner Should Know
The Fraud Examiner’s Report –  What the Certified Fraud Examiner Should KnowThe Fraud Examiner’s Report –  What the Certified Fraud Examiner Should Know
The Fraud Examiner’s Report – What the Certified Fraud Examiner Should Know
Godwin Emmanuel Oyedokun MBA MSc PhD FCA FCTI FCNA CFE FFAR
 
WORK PERMIT IN NORWAY | WORK VISA SERVICE
WORK  PERMIT  IN  NORWAY | WORK VISA SERVICEWORK  PERMIT  IN  NORWAY | WORK VISA SERVICE
WORK PERMIT IN NORWAY | WORK VISA SERVICE
RKIMT
 
Electrical Testing Lab Services in Dubai.pptx
Electrical Testing Lab Services in Dubai.pptxElectrical Testing Lab Services in Dubai.pptx
Electrical Testing Lab Services in Dubai.pptx
sandeepmetsuae
 

Recently uploaded (20)

Best Immigration Consultants in Amritsar- SAGA Studies
Best Immigration Consultants in Amritsar- SAGA StudiesBest Immigration Consultants in Amritsar- SAGA Studies
Best Immigration Consultants in Amritsar- SAGA Studies
 
Greeting powerpoint slide for kids( 4-6 years old)
Greeting powerpoint slide for kids( 4-6 years old)Greeting powerpoint slide for kids( 4-6 years old)
Greeting powerpoint slide for kids( 4-6 years old)
 
DOJO Training room | Training DOJO PPT
DOJO Training room | Training DOJO   PPTDOJO Training room | Training DOJO   PPT
DOJO Training room | Training DOJO PPT
 
Generate Revenue with Contact Center Business Model Strategy
Generate Revenue with Contact Center Business Model StrategyGenerate Revenue with Contact Center Business Model Strategy
Generate Revenue with Contact Center Business Model Strategy
 
METS Lab SASO Certificate Services in Dubai.pdf
METS Lab SASO Certificate Services in Dubai.pdfMETS Lab SASO Certificate Services in Dubai.pdf
METS Lab SASO Certificate Services in Dubai.pdf
 
Understanding Love Compatibility or Synastry: Why It Matters
Understanding Love Compatibility or Synastry: Why It MattersUnderstanding Love Compatibility or Synastry: Why It Matters
Understanding Love Compatibility or Synastry: Why It Matters
 
Discover How Long Do Aluminum Gutters Last?
Discover How Long Do Aluminum Gutters Last?Discover How Long Do Aluminum Gutters Last?
Discover How Long Do Aluminum Gutters Last?
 
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
How Do Love Spells Really Work? The Secret to Get Your Ex Back Fast, Powerful...
 
The study compares AMUSE's FDM and MJF 3D printing technologies.pptx
The study compares AMUSE's FDM and MJF 3D printing technologies.pptxThe study compares AMUSE's FDM and MJF 3D printing technologies.pptx
The study compares AMUSE's FDM and MJF 3D printing technologies.pptx
 
Siddhivinayak temple timings Houston, TX
Siddhivinayak temple timings Houston, TXSiddhivinayak temple timings Houston, TX
Siddhivinayak temple timings Houston, TX
 
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdfThe best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
The best Social Media Spy Apps for Catching Your Unfaithful Wife.pdf
 
Bridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
Bridging the Language Gap The Power of Simultaneous Interpretation in RwandaBridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
Bridging the Language Gap The Power of Simultaneous Interpretation in Rwanda
 
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
Sustainable Solutions for Chemical Waste Disposal by Summerland Environmental...
 
x ray baggage scanner manufacturers in India
x ray baggage scanner manufacturers in Indiax ray baggage scanner manufacturers in India
x ray baggage scanner manufacturers in India
 
Emmanuel Katto Uganda - A Philanthropist
Emmanuel Katto Uganda - A PhilanthropistEmmanuel Katto Uganda - A Philanthropist
Emmanuel Katto Uganda - A Philanthropist
 
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptxTop Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
Top Challenges Faced by High-Risk Merchants and How to Overcome Them.pptx
 
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptxBiomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
Biomass Briquettes A Sustainable Solution for Energy and Waste Management..pptx
 
The Fraud Examiner’s Report – What the Certified Fraud Examiner Should Know
The Fraud Examiner’s Report –  What the Certified Fraud Examiner Should KnowThe Fraud Examiner’s Report –  What the Certified Fraud Examiner Should Know
The Fraud Examiner’s Report – What the Certified Fraud Examiner Should Know
 
WORK PERMIT IN NORWAY | WORK VISA SERVICE
WORK  PERMIT  IN  NORWAY | WORK VISA SERVICEWORK  PERMIT  IN  NORWAY | WORK VISA SERVICE
WORK PERMIT IN NORWAY | WORK VISA SERVICE
 
Electrical Testing Lab Services in Dubai.pptx
Electrical Testing Lab Services in Dubai.pptxElectrical Testing Lab Services in Dubai.pptx
Electrical Testing Lab Services in Dubai.pptx
 

Deadlock avoidance and prevention .. computer networking

  • 3. Deadlock is:  A set of blocked processes each holding a resource and waiting to acquire a resource held by another process in the set.
  • 4. There are three policy conditions that must hold for a deadlock to be possible (the “necessary conditions”): 1. Mutual Exclusion 2. Hold-and-Wait 3. No Preemption 4. Circular Wait The (4) Conditions for Deadlock
  • 5.  Deadlock occurs if and only if the circular wait condition is unresolvable  The circular wait condition is unresolvable if the first 3 policy conditions hold  So the 4 conditions taken together constitute necessary and sufficient conditions for deadlock The Conditions for Deadlock
  • 6. Approaches to handle deadlock  Deadlock Prevention  Deadlock Avoidance  Deadlock Detection and Recovery
  • 7. 1. A process acquires all the needed resources simultaneously before it begins its execution, therefore breaking the hold and wait condition. Deadlock Prevention E.g. In the dining philosophers’ problem, each philosopher is required to pick up both forks at the same time. If he fails, he has to release the fork(s) (if any) he has acquired.
  • 8. 2. All resources are assigned unique numbers. A process may request a resource with a unique number I only if it is not holding a resource with a number less than or equal to I and therefore breaking the circular wait condition. E.g. In the dining philosophers problem, each philosopher is required to pick a fork that has a larger id than the one he currently holds. That is, philosopher P5 needs to pick up fork F5 and then F1; the other philosopher Pi should pick up fork Fi followed by Fi-1.
  • 9. 3. Each process is assigned a unique priority number. The priority numbers decide whether process Pi should wait for process Pj and therefore break the non-preemption condition. 4. Practically it is impossible to provide a method to break the mutual exclusion condition since most resources are intrinsically non-sharable, e.g., two philosophers cannot use the same fork at the same time.
  • 10. Deadlock Avoidance Avoid actions that may lead to deadlock. Think of it as a safe state moving from one state to another as instruction is executed. We can avoid the situation of deadlock by : 1.Safe state 2. Bankers Algorithm 3.Resource allocation graph
  • 11. Safe state " ■ System is in safe state if there exists a safe sequence of all processes." When a process requests an available resource, system must decide if immediate allocation leaves the system in a safe state. ■ Sequence <P1, P2, …, Pn> is safe if for each Pi, the resources that Pi can still request can be satisfied by currently available resources + resources held by all the Pj, with j<I." ● If Pi resource needs are not immediately available, then Pi can wait until all Pj have finished.“ ● When Pj is finished, Pi can obtain needed resources, execute, return allocated resources, and terminate. " ● When Pi terminates, Pi+1 can obtain its needed resources, and so on. "
  • 12. A resource allocation graph is generally used to avoid deadlocks. If there are no cycles in the resource allocation graph, then there are no deadlocks. If there are cycles, there may be a deadlock. If there is only one instance of every resource, then a cycle implies a deadlock. Consider the image with calm edges as below: If R2 is allocated to p2 and if P1 request for R2, there will be a deadlock. Resource allocation graph
  • 13. Example: The banker knows that all 4 clients need 22 units together, but he has only total 10 units Banker’s Algorithm: ADAM 0 6 EVE 0 5 JOE 0 4 MARY 0 7 ADAM 1 6 EVE 1 5 JOE 2 4 MARY 4 7 ADAM 1 6 EVE 2 5 JOE 2 4 MARY 4 7 The Banker algorithm, sometimes referred to as the detection algorithm, is a resource allocation and deadlock avoidance algorithm developed by Edsger Dijkstra that tests for safety by simulating the allocation of predetermined maximum possible amounts of all resources, and then makes an "s-state" check to test for possible deadlock conditions for all other pending activities, before deciding whether allocation should be allowed to continue.
  • 14. Data Structures for the Banker’s Algorithm • Available: Vector of length m. If available [j] = k, there are k instances of resource type Rj available. • Max: n x m matrix. If Max [i,j] = k, then process Pi may request at most k instances of resource type Rj. • Allocation: n x m matrix. If Allocation[i,j] = k then Pi is currently allocated k instances of Rj. • Need: n x m matrix. If Need[i,j] = k, then Pi may need k more instances of Rj to complete its task. Need [i,j] = Max[i,j] – Allocation [i,j]. Let n = number of processes, and m = number of resources types.
  • 15. Safety Algorithm 1. Let Work and Finish be vectors of length m and n, respectively. Initialize: Work = Available Finish [i] = false for i = 1,2, …, n. 2. Find and i such that both: (a) Finish [i] = false (b) Needi Work If no such i exists, go to step 4. 3. Work = Work + Allocationi Finish[i] = true go to step 2 4. If Finish [i] == true for all i, then the system is in a safe state.
  • 16. Requesti = request vector for process Pi. Requesti [ j ] == k means that process Pi wants k instances of resource type Rj. 1. If Requesti Needi go to step 2. Otherwise, raise error condition, since process has exceeded its maximum claim 2. If Requesti Available, go to step 3. Otherwise Pi must wait, since resources are not available. 3. Test to allocate requested resources to Pi by modifying the state as follows: Available = Available - Requesti; Allocationi = Allocationi + Requesti; Needi = Needi – Requesti; • If safe == the resources are allocated to Pi. • If unsafe == Pi must wait, and the old resource-allocation state is restored Resource-Request Algorithm for Process Pi