Skip to main content

Deadlock conditions; Banker's with 4 processes

Short answer

Deadlock requires mutual exclusion, hold and wait, no preemption, and circular wait. Banker's algorithm shows the state is SAFE: safe sequence P4 → P1 → P3 → P2.

Write four conditions for deadlock. A system has four processes P1, P2, P3, P4 and three resources R1, R2, R3 with existing resource E = (15 9 5). After following allocation, resource available becomes A = (3 2 0). Use Banker's algorithm to test whether the given state is safe or not. If it is safe state, show the sequence of execution of processes.

Allocation (R1 R2 R3)Maximum (R1 R2 R3)Need (R1 R2 R3)
P13 0 13 2 20 2 1
P25 4 16 8 21 4 1
P32 2 03 2 41 0 4
P42 1 34 2 32 1 0

Four conditions for deadlock

  1. Mutual exclusion: a resource is held by one process at a time.
  2. Hold and wait: a process holds some resources while waiting for others.
  3. No preemption: resources cannot be forcibly taken away.
  4. Circular wait: a closed chain of processes exists, each waiting for a resource held by the next.

Banker's algorithm

E = (15 9 5). Total allocation = (3+5+2+2, 0+4+2+1, 1+1+0+3) = (12, 7, 5), so Available = E − allocation = (3, 2, 0), matching the given A. Need = Maximum − Allocation is as given in the table.

Work = (3, 2, 0)

StepProcessNeedNeed ≤ Work?Work after (Work + Allocation)
1P10 2 12 ≤ 2 but 1 > 0, no–
1P21 4 14 > 2, no–
1P31 0 44 > 0, no–
1P42 1 0yes (2≤3, 1≤2, 0≤0)3 2 0 + 2 1 3 = 5 3 3
2P10 2 1yes (0≤5, 2≤3, 1≤3)5 3 3 + 3 0 1 = 8 3 4
3P31 0 4yes (1≤8, 0≤3, 4≤4)8 3 4 + 2 2 0 = 10 5 4
4P21 4 1yes (1≤10, 4≤5, 1≤4)10 5 4 + 5 4 1 = 15 9 5

All four processes can finish and Work finally equals E = (15 9 5).

Answer: The state is SAFE. Safe sequence: P4 → P1 → P3 → P2.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 7 questions →