---
title: "Deadlock conditions; Banker's safe sequence"
subject: "Operating System"
chapter: 7
key: "semester_6/operating_system:four-conditions-banker-snapshot-332"
source: https://www.bctengineer.com/q/semester_6/operating_system/four-conditions-banker-snapshot-332
site: BCT Engineering
---

# Deadlock conditions; Banker's safe sequence

Operating System · Chapter 7: Deadlock

- Asked in: 2075 Baisakh, 10 marks
- Video: [4. Deadlock avoidance | #Bankers algorithm | #Safetyalgorithm | Operating system](https://www.youtube.com/watch?v=d_Kr-Z-UzEg) — Preethi J
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/four-conditions-banker-snapshot-332
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

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.

## 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.

## Answer

#### 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:

| 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>.**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which set lists the four necessary conditions for deadlock?
   A. Mutual exclusion, hold and wait, no preemption, circular wait
   B. Mutual exclusion, starvation, preemption, circular wait
   C. Hold and wait, aging, no preemption, spooling
   D. Mutual exclusion, hold and wait, preemption, safe state
   Answer: A. Deadlock needs all four Coffman conditions together: mutual exclusion, hold and wait, no preemption and circular wait. (Key point: Four conditions)

2. What is P1's Need, with Max (3,2,2) and Allocation (2,0,0)?
   A. (5, 2, 2)
   B. (3, 2, 2)
   C. (1, 2, 2)
   D. (1, 0, 0)
   Answer: C. Need = Max - Allocation = (1,2,2). (Key point: Need)

3. With Work = (3,3,2), which process can run first and why not P0?
   A. P0, since it holds the fewest resources
   B. P2, since its Need is smallest
   C. P4, since it holds a C resource
   D. P1, since Need (1,2,2) <= Work; P0 needs 7 of A, more than 3
   Answer: D. A process may run only if Need <= Work in every resource; P0's A need is 7 > 3. (Key point: First process)

4. What does the algorithm conclude?
   A. Safe; sequence P1, P3, P0, P2, P4 ends with Work = (10,5,7)
   B. Unsafe; P0 can never finish
   C. Safe; sequence P0, P1, P2, P3, P4
   D. Unsafe; Work never exceeds (7,4,3)
   Answer: A. All five processes finish and Work returns to the total (10,5,7), so the state is safe. (Key point: Safe sequence)

## Related in Operating System

- [Deadlock conditions; Banker's with 4 processes](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afour-conditions-banker-p1-p4) — Operating System, chapter 7
- [Deadlock vs postponement; Banker's 4 resources](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-vs-postponement-banker-6442) — Operating System, chapter 7
- [Banker's algorithm, 5 processes, 4 resources](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Abanker-five-process-four-resource) — Operating System, chapter 7
- [Deadlock detection with allocation matrices](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-detection-matrices) — Operating System, chapter 7
- [Deadlock; necessary conditions with examples](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-necessary-conditions-examples) — Operating System, chapter 7
- [Deadlock conditions and why all necessary](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-why-necessary) — Operating System, chapter 7

## Related in other subjects

- [Get data from P0, send to P1 (asm and C)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3A8051-p0-to-p1-assembly-c) — Embedded System, chapter 9
- [Liang-Barsky: P1(-5,3), P2(15,9)](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aliang-barsky-0-0-10-10) — Computer Graphics, chapter 3
