- 2069 Bhadra · 2+8 marks
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) | |
|---|---|---|---|
| P1 | 3 0 1 | 3 2 2 | 0 2 1 |
| P2 | 5 4 1 | 6 8 2 | 1 4 1 |
| P3 | 2 2 0 | 3 2 4 | 1 0 4 |
| P4 | 2 1 3 | 4 2 3 | 2 1 0 |
Four conditions for deadlock
- Mutual exclusion: a resource is held by one process at a time.
- Hold and wait: a process holds some resources while waiting for others.
- No preemption: resources cannot be forcibly taken away.
- 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)
| Step | Process | Need | Need ≤ Work? | Work after (Work + Allocation) |
|---|---|---|---|---|
| 1 | P1 | 0 2 1 | 2 ≤ 2 but 1 > 0, no | – |
| 1 | P2 | 1 4 1 | 4 > 2, no | – |
| 1 | P3 | 1 0 4 | 4 > 0, no | – |
| 1 | P4 | 2 1 0 | yes (2≤3, 1≤2, 0≤0) | 3 2 0 + 2 1 3 = 5 3 3 |
| 2 | P1 | 0 2 1 | yes (0≤5, 2≤3, 1≤3) | 5 3 3 + 3 0 1 = 8 3 4 |
| 3 | P3 | 1 0 4 | yes (1≤8, 0≤3, 4≤4) | 8 3 4 + 2 2 0 = 10 5 4 |
| 4 | P2 | 1 4 1 | yes (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)
Related questions
- Deadlock vs postponement; Banker's 4 resources · Operating System, chapter 7
- Deadlock conditions; Banker's safe sequence · Operating System, chapter 7
- Banker's algorithm, 5 processes, 4 resources · Operating System, chapter 7
- Deadlock detection with allocation matrices · Operating System, chapter 7
- Four deadlock conditions; prevention, recovery · Operating System, chapter 7
- Deadlock, postponement, prevention, 2 processes · Operating System, chapter 7
- Show i1 = i2 = -V/(R1+R2+R3) at t=0+ · Electrical Circuit Theory, chapter 2
- Liang-Barsky: P1(-5,3), P2(15,9) · Computer Graphics, chapter 3
- IDMT grading: R1, R2 with 1000/5 CTs · Switchgear and Protection, chapter 7 · asked 2×
- Non-preemptive SJF with P4 arriving · Embedded System, chapter 6 · asked 2×