Deadlock Detection and Recovery
Detection and Recovery
Unlike prevention, detection does not require restricting requests in advance to break a necessary condition. The OS can run detection periodically. Waiting cycles suffice for single-instance resources; multiple-instance resources also require checking requests and available quantities.
When deadlock is found, common recovery methods include:
- Abort: terminate some or all deadlocked processes and reclaim their resources, considering process priority and termination cost.
- Rollback: restore one or more processes to a state that avoids deadlock and releases resources. This requires stored history and restoration points.
Detect a cycle and choose a recovery victim
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Dining Philosophers
Taking the left chopstick before the right can deadlock. To let all philosophers eat, the algorithm must prevent deadlock and starvation. Allowing at most four philosophers into the dining room prevents a five-way waiting ring, letting at least one obtain two chopsticks and release them after eating. This is prevention; avoiding starvation additionally requires fair admission and resource allocation.
Semaphore capacity = 4;
Process philosopher(index) {
do {
wait(capacity);
wait(chopstick[index]);
wait(chopstick[(index + 1) % 5]);
eat;
signal(chopstick[(index + 1) % 5]);
signal(chopstick[index]);
signal(capacity);
} while (true);
}Choose a victim that actually breaks the cycle
P1 waits for P2, P2 waits for P1, and P3 waits for P2; every relevant resource has one instance.
- Draw the wait-for graph and distinguish cycle members from a blocked dependent.
- Compare aborting P3 with aborting P1 under safe-release assumptions.
- Specify recovery costs and explain why four-seat dining admission is prevention, not post-deadlock recovery.