Deadlock in OS | Conditions for Deadlock

Spread the love

Deadlock in OS-

 

Deadlock is a situation where-

  • The execution of two or more processes is blocked because each process holds some resource and waits for another resource held by some other process.

 

Example-

 

 

Here

  • Process P1 holds resource R1 and waits for resource R2 which is held by process P2.
  • Process P2 holds resource R2 and waits for resource R1 which is held by process P1.
  • None of the two processes can complete and release their resource.
  • Thus, both the processes keep waiting infinitely.

 

Conditions For Deadlock-

 

There are following 4 necessary conditions for the occurrence of deadlock-

  1. Mutual Exclusion
  2. Hold and Wait
  3. No preemption
  4. Circular wait

 

1. Mutual Exclusion-

 

By this condition,

  • There must exist at least one resource in the system which can be used by only one process at a time.
  • If there exists no such resource, then deadlock will never occur.
  • Printer is an example of a resource that can be used by only one process at a time.

 

2. Hold and Wait-

 

By this condition,

  • There must exist a process which holds some resource and waits for another resource held by some other process.

 

3. No Preemption-

 

By this condition,

  • Once the resource has been allocated to the process, it can not be preempted.
  • It means resource can not be snatched forcefully from one process and given to the other process.
  • The process must release the resource voluntarily by itself.

 

4. Circular Wait-

 

By this condition,

  • All the processes must wait for the resource in a cyclic manner where the last process waits for the resource held by the first process.

 

 

Here,

  • Process P1 waits for a resource held by process P2.
  • Process P2 waits for a resource held by process P3.
  • Process P3 waits for a resource held by process P4.
  • Process P4 waits for a resource held by process P1.

 

Important Note-

 

  • All these 4 conditions must hold simultaneously for the occurrence of deadlock.
  • If any of these conditions fail, then the system can be ensured deadlock free.

 

To gain better understanding about Deadlock in OS,

Watch this Video Lecture

 

Next Article- Deadlock Handling Strategies

 

Get more notes and other study material of Operating System.

Watch video lectures by visiting our YouTube channel LearnVidFun.

Summary
Deadlock in OS | Conditions for Deadlock
Article Name
Deadlock in OS | Conditions for Deadlock
Description
Deadlock in OS is a situation where two or more processes are blocked. Conditions for Deadlock- Mutual Exclusion, Hold and Wait, No preemption, Circular wait. These 4 conditions must hold simultaneously for the occurrence of deadlock.
Author
Publisher Name
Gate Vidyalay
Publisher Logo

Spread the love