Tag: Deadlock Handling Strategies

Deadlock Detection | Deadlock Prevention

Deadlock Handling-


Before you go through this article, make sure that you have gone through the previous article on Deadlock in OS.


The various strategies for handling deadlock are-



  1. Deadlock Prevention
  2. Deadlock Avoidance
  3. Deadlock Detection and Recovery
  4. Deadlock Ignorance


Deadlock Prevention-


  • This strategy involves designing a system that violates one of the four necessary conditions required for the occurrence of deadlock.
  • This ensures that the system remains free from the deadlock.


The various conditions of deadlock occurrence may be violated as-


1. Mutual Exclusion-


  • To violate this condition, all the system resources must be such that they can be used in a shareable mode.
  • In a system, there are always some resources which are mutually exclusive by nature.
  • So, this condition can not be violated.


2. Hold and Wait-


This condition can be violated in the following ways-




In this approach,

  • A process has to first request for all the resources it requires for execution.
  • Once it has acquired all the resources, only then it can start its execution.
  • This approach ensures that the process does not hold some resources and wait for other resources.




The drawbacks of this approach are-

  • It is less efficient.
  • It is not implementable since it is not possible to predict in advance which resources will be required during execution.




In this approach,

  • A process is allowed to acquire the resources it desires at the current moment.
  • After acquiring the resources, it start its execution.
  • Now before making any new request, it has to compulsorily release all the resources that it holds currently.
  • This approach is efficient and implementable.




In this approach,

  • A timer is set after the process acquires any resource.
  • After the timer expires, a process has to compulsorily release the resource.


3. No Preemption-


  • This condition can by violated by forceful preemption.
  • Consider a process is holding some resources and request other resources that can not be immediately allocated to it.
  • Then, by forcefully preempting the currently held resources, the condition can be violated.


A process is allowed to forcefully preempt the resources possessed by some other process only if-

  • It is a high priority process or a system process.
  • The victim process is in the waiting state.


4. Circular Wait-


  • This condition can be violated by not allowing the processes to wait for resources in a cyclic manner.
  • To violate this condition, the following approach is followed-




  • A natural number is assigned to every resource.
  • Each process is allowed to request for the resources either in only increasing or only decreasing order of the resource number.
  • In case increasing order is followed, if a process requires a lesser number resource, then it must release all the resources having larger number and vice versa.
  • This approach is the most practical approach and implementable.
  • However, this approach may cause starvation but will never lead to deadlock.


Deadlock Avoidance-


  • This strategy involves maintaining a set of data using which a decision is made whether to entertain the new request or not.
  • If entertaining the new request causes the system to move in an unsafe state, then it is discarded.
  • This strategy requires that every process declares its maximum requirement of each resource type in the beginning.
  • The main challenge with this approach is predicting the requirement of the processes before execution.
  • Banker’s Algorithm is an example of a deadlock avoidance strategy.


Deadlock Detection and Recovery-


  • This strategy involves waiting until a deadlock occurs.
  • After deadlock occurs, the system state is recovered.
  • The main challenge with this approach is detecting the deadlock.


Deadlock Ignorance-


  • This strategy involves ignoring the concept of deadlock and assuming as if it does not exist.
  • This strategy helps to avoid the extra overhead of handling deadlock.
  • Windows and Linux use this strategy and it is the most widely used method.
  • It is also called as Ostrich approach.


To gain better understanding about Deadlock Handling Strategies,

Watch this Video Lecture


Next Article- Practice Problems On Deadlock


Get more notes and other study material of Operating System.

Watch video lectures by visiting our YouTube channel LearnVidFun.