- 2068 Bhadra · 8 marks
- Year not given
Banker's algorithm, 5 processes, 4 resources
Short answer
The state is SAFE. A safe sequence is P2 → P4 → P5 → P1 → P3.
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 |
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.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Deadlock conditions; Banker's with 4 processes · Operating System, chapter 7
- Deadlock conditions; Banker's safe sequence · Operating System, chapter 7
- Deadlock vs postponement; Banker's 4 resources · Operating System, chapter 7
- Deadlock, postponement, prevention, 2 processes · Operating System, chapter 7
- Deadlock occurrence and avoidance methods · Operating System, chapter 7
- Lock, deadlock; deadlock avoidance · Distributed System, chapter 8
- Current process models; why waterfall is not accurate · Software Engineering, chapter 1