- 2072 Asoj · 2+4+4 marks
Deadlock conditions; detection with example
Short answer
Deadlock occurs when processes wait for each other's resources. The four essential conditions are mutual exclusion, hold and wait, no preemption, circular wait. Detection uses a resource allocation graph; a cycle indicates deadlock. Example: P1 holds A and requests B, P2 holds B and requests A, forming a cycle and deadlock.
What is deadlock? Explain the essential condition for deadlock. How do you detect deadlock? Explain with example.
Deadlock
Deadlock is a state in which a set of processes are all blocked, each waiting for a resource that is held by another process of the set.
Essential conditions
- Mutual exclusion: resources are non-sharable.
- Hold and wait: a process holds a resource while waiting for another.
- No preemption: resources are released only voluntarily.
- Circular wait: a circular chain of waiting processes exists.
Detecting deadlock
Resource allocation graph (RAG). Draw processes as circles and resources as boxes; an edge R → P means R is allocated to P, and P → R means P is requesting R. If every resource has a single instance, a cycle in the RAG means deadlock.
Matrix method (multiple instances). Keep Available (A), Allocation (C) and Request (R). Set Work = A, mark processes with zero allocation as finished, then repeatedly select a process whose Request ≤ Work, add its Allocation to Work and mark it finished. Processes still unmarked at the end are deadlocked.
Example
Take two processes and two resource types A and B with one instance each.
P1 holds A, requests B
P2 holds B, requests A
A --> P1 --> B --> P2 --> A (cycle)
Allocation: P1 = (1,0), P2 = (0,1); Request: P1 = (0,1), P2 = (1,0); Available = (0,0).
Work = (0,0). P1's request (0,1) is not ≤ (0,0), and P2's request (1,0) is not ≤ (0,0). No process can be marked, so both P1 and P2 remain unmarked and the system is deadlocked. The cycle A → P1 → B → P2 → A in the RAG shows the same thing.
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Deadlock conditions, detection, action · Operating System, chapter 7
- Deadlock detection with examples · Operating System, chapter 7
- Four deadlock conditions; prevention, recovery · Operating System, chapter 7
- Deadlock; necessary conditions with examples · Operating System, chapter 7
- Deadlock conditions; Banker's with 4 processes · Operating System, chapter 7
- Deadlock conditions and why all necessary · Operating System, chapter 7
- Essential and natural boundary conditions · Finite Element Method, chapter 2
- Deadlock and Coffman conditions · Embedded System, chapter 6 · asked 4×
- Deadlock and its conditions · Microprocessor, chapter 6 · asked 2×
- Back-face detection algorithm · Computer Graphics, chapter 7 · asked 8×