Deadlock Avoidance

In deadlock avoidance, the operating system is provided with extra information related to all resources any process will require during its lifetime. Then at every request, the system can decide whether to grant that request or not. This decision depends upon

  • resources currently available
  • resources currently allocated to each process
  • future request and release of resources by each process

Important Terms to remember in deadlock avoidance

Safe State: state is safe if the system can allocate resources to every process in some order and still avoid deadlock.
Safe sequence – is an order {P1, P2, … Pn} in which the processes can be allocated resources safely.


Safe state – No deadlock
Unsafe State – Deadlock may or may not occur

Q. System has total 12 magnetic tapes and 3 processes. Individual process requirement is as below

safe system state
System State: safe

Q. Is the system in safe state at time T0 ?
Yes. Safe sequence is <P1,P0,P2>
Magnetic tapes remaining with system = 12-(5+2+2) = 3
P1 can be allocated its remaining two magnetic tapes.
After P1 finishes Magnetic tapes remaining with system = 5
P0 needs 5 more magnetic tapes which can be allocated. After P0 finishes P2’s need of remaining 7 tapes can be fulfilled.

Q. Suppose P2 requests for 1 more magnetic tape at time T1. Should this request be granted?
Ans: No
Reason: Let us suppose the request is granted. The modified system state will be

unsafe system state
System state: unsafe

No safe sequence exists.
Remaining tapes with the system = 2
Request of P1 can be fulfilled. After P1 finishes tapes available = 4
P0 needs 5 and P2 needs 6 tapes. Both will keep on waiting, resulting in a deadlock


  • Do not grant the request immediately
  • Check whether granting the request will leave the system in safe state or not?
  • If yes, grant the request
  • If no, do not grant the request
  • Disadvantage
  • Low resource utilization

Algorithms for deadlock avoidance

  1. Resource allocation graph algorithm
  2. Banker’s algorithm

PPT on Deadlock Avoidance

The above discussion is summarized in the form of a PPT with animations below.
Note: Click within the slide area for animations. Clicking on the “next” slide button will not display any animation

Video on Deadlock Avoidance

Previous                                   Next
Deadlock Prevention       Resource Allocation Graph

Leave a Reply