---
title: "Banker's algorithm, 5 processes, 4 resources"
subject: "Operating System"
chapter: 7
key: "semester_6/operating_system:banker-five-process-four-resource"
source: https://www.bctengineer.com/q/semester_6/operating_system/banker-five-process-four-resource
site: BCT Engineering
---

# Banker's algorithm, 5 processes, 4 resources

Operating System · Chapter 7: Deadlock

- Asked in: 2068 Bhadra, 8 marks; year not given
- Video: [Deadlock Avoidance | Banker's Algorithm (Example) | Part 1](https://www.youtube.com/watch?v=BAvtF6MCdgo) — making IT simple
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/banker-five-process-four-resource
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

A system that uses the Banker's Algorithm deadlock avoidance has five processes (1, 2, 3, 4 and 5) and four types of resources (A, B, C and D). There are multiple resources of each type. Is the following state safe or not? If it is, show how the processes can complete. If not, show how they can deadlock.
| Process | Current loan (A B C D) | Max need (A B C D) | Current claim (A B C D) |
|---|---|---|---|
| 1 | 1 0 2 0 | 3 2 4 2 | 2 2 2 2 |
| 2 | 0 3 1 2 | 3 5 1 2 | 3 2 0 0 |
| 3 | 2 4 5 1 | 2 7 7 5 | 0 3 2 4 |
| 4 | 3 0 0 6 | 5 5 0 8 | 2 5 0 2 |
| 5 | 4 2 1 3 | 6 2 1 4 | 2 0 0 1 |
Resources Available: A B C D = 3 4 0 1
Total Resources: A B C D = 13 13 9 13

## Short answer

The state is SAFE. A safe sequence is P2 → P4 → P5 → P1 → P3.

## Answer

#### Idea
The state is **safe** if there is some order in which every process can obtain its remaining claim and finish. Banker's algorithm: repeatedly find a process whose claim (need) ≤ Work (available); let it finish and release its loan, adding it to Work.

Check of data: sum of current loans = (10, 9, 9, 12); adding available (3, 4, 0, 1) gives (13, 13, 9, 13), equal to the total resources, so the data are consistent. Claim = Max − Loan, as given.

Work = Available = (3, 4, 0, 1)

| Step | Process chosen | Claim | Work before | Condition | Work after (Work + Loan) |
|---|---|---|---|---|---|
| 1 | P2 | 3 2 0 0 | 3 4 0 1 | 3≤3, 2≤4, 0≤0, 0≤1 yes | 3 7 1 3 |
| 2 | P4 | 2 5 0 2 | 3 7 1 3 | yes | 6 7 1 9 |
| 3 | P5 | 2 0 0 1 | 6 7 1 9 | yes | 10 9 2 12 |
| 4 | P1 | 2 2 2 2 | 10 9 2 12 | yes | 11 9 4 12 |
| 5 | P3 | 0 3 2 4 | 11 9 4 12 | yes | 13 13 9 13 |

At the start only P2 and P5 can proceed (P1 needs C = 2 but only 0 is available; P3 needs C = 2 and D = 4; P4 needs B = 5 > 4). So more than one safe sequence exists; P2 is taken first here. P4 can run only after P2 or P5 has returned its resources.

All five processes finish, and the final Work equals the total resources (13, 13, 9, 13).

**Answer: The state is SAFE. One safe sequence is P2 → P4 → P5 → P1 → P3.**

## Check yourself

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

1. When is a state safe in Banker's algorithm?
   A. Available resources exceed total resources
   B. Some order exists in which every process can obtain its claim and finish
   C. Every process can finish at once
   D. No process holds any resource
   Answer: B. A safe sequence exists if each process in turn can have its remaining claim met. (Key point: Safe state meaning)

2. What is the step rule?
   A. Pick a process with claim <= Work, then add its loan to Work
   B. Pick a process with loan <= Work and subtract its claim
   C. Pick the process with the largest max need
   D. Pick a process with claim > Work
   Answer: A. After finishing, the process releases its loan, which increases Work. (Key point: Safety step)

3. With Work = (3,4,0,1), why can P2 run first (claim 3 2 0 0)?
   A. It holds the most resources
   B. P2's max need is smallest
   C. Its claim is within Work in every resource type
   D. Resource C is plentiful
   Answer: C. 3<=3, 2<=4, 0<=0, 0<=1. (Key point: First process)

4. What is the result and a valid safe sequence?
   A. Unsafe: deadlock among P1 and P3
   B. Safe: P1, P2, P3, P4, P5
   C. Unsafe: P4 can never run
   D. Safe: P2, P4, P5, P1, P3
   Answer: D. Final Work (13,13,9,13) equals total resources so all finish. (Key point: Result)

## 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 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
- [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, 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
- [Deadlock occurrence and avoidance methods](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-avoidance-methods-examples) — Operating System, chapter 7

## Related in other subjects

- [Lock, deadlock; deadlock avoidance](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Alock-deadlock-avoidance) — Distributed System, chapter 8
- [Current process models; why waterfall is not accurate](https://www.bctengineer.com/question.md?key=semester_5%2Fsoftware_engineering%3Awaterfall-not-accurate) — Software Engineering, chapter 1
