- 2075 Baisakh · 10 marks
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.
| Process | Allocation (A B C) | Max (A B C) |
|---|---|---|
| P0 | 0 1 0 | 7 5 3 |
| P1 | 2 0 0 | 3 2 2 |
| P2 | 3 0 2 | 9 0 2 |
| P3 | 2 1 1 | 2 2 2 |
| P4 | 0 0 2 | 4 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
- Mutual exclusion: resources are used by one process at a time.
- Hold and wait: a process holds resources while waiting for others.
- No preemption: resources are released only voluntarily.
- Circular wait: a cycle of processes exists, each waiting for a resource held by the next.
Banker's algorithm
Need = Max − Allocation:
| Process | Allocation | Max | Need |
|---|---|---|---|
| P0 | 0 1 0 | 7 5 3 | 7 4 3 |
| P1 | 2 0 0 | 3 2 2 | 1 2 2 |
| P2 | 3 0 2 | 9 0 2 | 6 0 0 |
| P3 | 2 1 1 | 2 2 2 | 0 1 1 |
| P4 | 0 0 2 | 4 3 3 | 4 3 1 |
Available = Work = (3, 3, 2). (Total resources = Allocation sum (7, 2, 5) + Available = (10, 5, 7).)
| Step | Process | Need | Need ≤ Work | Work after |
|---|---|---|---|---|
| 1 | P1 | 1 2 2 | yes (1≤3, 2≤3, 2≤2) | 3 3 2 + 2 0 0 = 5 3 2 |
| 2 | P3 | 0 1 1 | yes | 5 3 2 + 2 1 1 = 7 4 3 |
| 3 | P0 | 7 4 3 | yes (7≤7, 4≤4, 3≤3) | 7 4 3 + 0 1 0 = 7 5 3 |
| 4 | P2 | 6 0 0 | yes | 7 5 3 + 3 0 2 = 10 5 5 |
| 5 | P4 | 4 3 1 | yes | 10 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)
Related questions
- Deadlock conditions; Banker's with 4 processes · Operating System, chapter 7
- Deadlock vs postponement; Banker's 4 resources · Operating System, chapter 7
- Banker's algorithm, 5 processes, 4 resources · Operating System, chapter 7
- Deadlock detection with allocation matrices · Operating System, chapter 7
- Deadlock; necessary conditions with examples · Operating System, chapter 7
- Deadlock conditions and why all necessary · Operating System, chapter 7
- Get data from P0, send to P1 (asm and C) · Embedded System, chapter 9
- Liang-Barsky: P1(-5,3), P2(15,9) · Computer Graphics, chapter 3