Skip to main content

Deadlock conditions; Banker's safe sequence

Short answer

The four deadlock conditions are mutual exclusion, hold and wait, no preemption, and circular wait. Using Banker's algorithm with available resources (3,3,2), the need matrix is calculated and a safe sequence <P1, P3, P0, P2, P4> is found where each process's needs can be satisfied by current work, proving the system is in a safe state.

Write four necessary conditions for deadlock. Consider the following snapshot of a system.

ProcessAllocation (A B C)Max (A B C)
P00 1 07 5 3
P12 0 03 2 2
P23 0 29 0 2
P32 1 12 2 2
P40 0 24 3 3
Let the available number of resources be given by available vector as (3, 3, 2). Use Banker's algorithm to claim that the system is in safe state and show the safe sequence.

Four necessary conditions

  1. Mutual exclusion: resources are used by one process at a time.
  2. Hold and wait: a process holds resources while waiting for others.
  3. No preemption: resources are released only voluntarily.
  4. Circular wait: a cycle of processes exists, each waiting for a resource held by the next.

Banker's algorithm

Need = Max − Allocation:

ProcessAllocationMaxNeed
P00 1 07 5 37 4 3
P12 0 03 2 21 2 2
P23 0 29 0 26 0 0
P32 1 12 2 20 1 1
P40 0 24 3 34 3 1

Available = Work = (3, 3, 2). (Total resources = Allocation sum (7, 2, 5) + Available = (10, 5, 7).)

StepProcessNeedNeed ≤ WorkWork after
1P11 2 2yes (1≤3, 2≤3, 2≤2)3 3 2 + 2 0 0 = 5 3 2
2P30 1 1yes5 3 2 + 2 1 1 = 7 4 3
3P07 4 3yes (7≤7, 4≤4, 3≤3)7 4 3 + 0 1 0 = 7 5 3
4P26 0 0yes7 5 3 + 3 0 2 = 10 5 5
5P44 3 1yes10 5 5 + 0 0 2 = 10 5 7

(P0 could not go in step 1 because its need for A = 7 > 3; P2 needs A = 6 > 3; P4 needs A = 4 > 3.) All processes complete, and Work = (10, 5, 7), the total.

Answer: The system is in a SAFE state. A safe sequence is <P1, P3, P0, P2, P4>.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 7 questions →