---
title: "Deadlock conditions; Banker's with 4 processes"
subject: "Operating System"
chapter: 7
key: "semester_6/operating_system:four-conditions-banker-p1-p4"
source: https://www.bctengineer.com/q/semester_6/operating_system/four-conditions-banker-p1-p4
site: BCT Engineering
---

# Deadlock conditions; Banker's with 4 processes

Operating System · Chapter 7: Deadlock

- Asked in: 2069 Bhadra, 2+8 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-p1-p4
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

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 |

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

## Answer

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

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

## Check yourself

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

1. How is Available found?
   A. Sum of Need
   B. Existing E minus total allocation: (15,9,5)-(12,7,5) = (3,2,0)
   C. Sum of Maximum
   D. E plus total allocation
   Answer: B. Available is what remains of the existing resources. (Key point: Available computation)

2. Which process can run first with Work (3,2,0)?
   A. P4, need (2,1,0)
   B. P1, need (0,2,1)
   C. P2, need (1,4,1)
   D. P3, need (1,0,4)
   Answer: A. Only P4's need fits in Work; the others need R3 or more R2. (Key point: First process)

3. What is the safe sequence?
   A. P1, P2, P3, P4
   B. P4, P2, P1, P3
   C. P4, P1, P3, P2
   D. P3, P4, P1, P2
   Answer: C. Work grows 533, 834, 1054, then 15 9 5. (Key point: Safe sequence)

4. How is Need calculated?
   A. Allocation - Maximum
   B. Maximum + Allocation
   C. Existing - Maximum
   D. Maximum - Allocation
   Answer: D. Need is what a process may still request. (Key point: Need formula)

## Related in Operating System

- [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
- [Deadlock conditions; Banker's safe sequence](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afour-conditions-banker-snapshot-332) — 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
- [Four deadlock conditions; prevention, recovery](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-prevention-recovery) — Operating System, chapter 7
- [Deadlock, postponement, prevention, 2 processes](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-postponement-two-process-three-resource) — Operating System, chapter 7

## Related in other subjects

- [Show i1 = i2 = -V/(R1+R2+R3) at t=0+](https://www.bctengineer.com/question.md?key=semester_3%2Felectrical_circuit_theory%3Aswitch-a-to-b-initial-values) — Electrical Circuit Theory, chapter 2
- [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
- [IDMT grading: R1, R2 with 1000/5 CTs](https://www.bctengineer.com/question.md?key=semester_6%2Fswitchgear_and_protection%3Aidmt-r1-r2-1000-5) — Switchgear and Protection, chapter 7, asked 2×
- [Non-preemptive SJF with P4 arriving](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-sjf-nonpreemptive-6-8-2) — Embedded System, chapter 6, asked 2×
