What this topic covers
8 subtopics- Prevention9
- Banker's algorithm8
- Detection8
- Avoidance6
- Conditions5
- Numericals5
- Recovery3
- Handling1
- Beginner 15
- Intermediate 15
- Advanced 15
About this topic
A deadlock is a set of processes each waiting for a resource another one holds. Questions test the four necessary conditions, how prevention, avoidance and detection differ, and above all Banker's algorithm numericals: compute the Need matrix, find a safe sequence, decide whether a request can be granted. The tables here show Allocation and Max (or Request) side by side with Available underneath; every sequence and decision was computed by running the algorithm. When several processes could finish, the lowest-numbered one is chosen first.
Free preview
Sample questions
Try each one first, then open the answer for the explanation and why the other options are wrong.
Which four conditions must hold at the same time for a deadlock to occur?
Show answer and explanation
Explanation
These are the Coffman conditions. Deadlock prevention works by making sure at least one of them can never hold.
Why the other options are wrong
- BThrashing and spooling are unrelated.
- CRace conditions and paging are unrelated.
- DStarvation and aging are scheduling ideas.
Run the safety algorithm (choose the lowest-numbered process that can finish, then start scanning again from P0). Which safe sequence does it produce?
| Process | Alloc A | Alloc B | Alloc C | Max A | Max B | Max 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 |
Show answer and explanation
Explanation
Need: P0 (7,4,3), P1 (1,2,2), P2 (6,0,0), P3 (0,1,1), P4 (4,3,1). Work (3,3,2): P1 fits → work (5,3,2). Rescan: P3 fits → (7,4,3). P0 fits → (7,5,3). P2 → (10,5,5). P4 → (10,5,7). (P1, P3, P4, P2, P0 from a textbook is also safe – it just uses a different choice rule.)
Why the other options are wrong
- AWith the rule, P1 is found before P3.
- BP0 needs 7 A but only 3 are free.
- DAlso safe, but not what this rule produces (it picks P0 before P4).
Four processes need at most 3, 4, 5 and 6 units of a resource. What is the minimum number of units that guarantees the system can never deadlock?
The answer is a number – work it out, then open the solution.
Show answer and explanation
Explanation
The worst case gives each one unit short of its maximum: 2 + 3 + 4 + 5 = 14 units, all stuck. One more makes deadlock impossible: 15.