---
title: "Four deadlock conditions; prevention, recovery"
subject: "Operating System"
chapter: 7
key: "semester_6/operating_system:deadlock-conditions-prevention-recovery"
source: https://www.bctengineer.com/q/semester_6/operating_system/deadlock-conditions-prevention-recovery
site: BCT Engineering
---

# Four deadlock conditions; prevention, recovery

Operating System · Chapter 7: Deadlock

- Asked in: 2073 Magh, 10 marks
- Video: [Deadlock in Operating System | 4 Conditions of Deadlocks | Deadlock Handling - Process Management](https://www.youtube.com/watch?v=UVo9mGARkhQ) — Simple Snippets
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/deadlock-conditions-prevention-recovery
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

List four essential conditions for deadlock. Explain each of them briefly. What would be necessary (in operating system) to prevent the deadlock? How is deadlock recovered? Explain.

## Short answer

Deadlock requires mutual exclusion, hold and wait, no preemption, and circular wait. Prevention ensures at least one condition cannot hold via spooling, requesting all resources initially, allowing preemption, or imposing resource ordering. Recovery uses process termination, resource preemption with rollback to checkpoints, or restarting processes from earlier checkpoints.

## Answer

#### Four essential conditions
1. **Mutual exclusion:** a resource can be held by only one process at a time (e.g. printer).
2. **Hold and wait:** a process holds at least one resource and waits for others.
3. **No preemption:** a resource can be released only voluntarily by the process holding it.
4. **Circular wait:** processes form a circle, each waiting for a resource held by the next.

#### Preventing deadlock
The OS must make sure at least one condition never holds.
- **Mutual exclusion:** spool shared devices (e.g. printer spooler) so no process holds the device directly.
- **Hold and wait:** a process must request all resources at the start, or release all held resources before requesting more.
- **No preemption:** if a request cannot be granted, the process releases everything it holds and retries later; or the OS preempts resources of waiting processes.
- **Circular wait:** give each resource type a number and let processes request only in increasing order; no cycle can form.

#### Recovery from deadlock
After detection, the system recovers by:
1. **Process termination:** abort all deadlocked processes, or abort one at a time until the deadlock disappears. The victim is chosen by priority, running time, resources used, resources needed.
2. **Resource preemption:** take a resource from one process and give it to another; roll the victim back to a safe state (checkpoint) and restart it. To avoid starvation, count rollbacks per process.
3. **Recovery by rollback:** processes periodically checkpoint their state; on deadlock, a process holding a needed resource is restarted from an earlier checkpoint, releasing it.

## Check yourself

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

1. Which set lists the four necessary conditions for deadlock?
   A. Mutual exclusion, hold and wait, no preemption, circular wait
   B. Mutual exclusion, starvation, preemption, circular wait
   C. Hold and wait, aging, no preemption, spooling
   D. Mutual exclusion, hold and wait, preemption, safe state
   Answer: A. Deadlock needs all four Coffman conditions together: mutual exclusion, hold and wait, no preemption and circular wait. (Key point: Four conditions)

2. What is 'hold and wait'?
   A. A resource can be held by only one process at a time
   B. A resource can be taken only voluntarily
   C. A chain of processes each waits for the next
   D. A process holds at least one resource while waiting for others
   Answer: D. Hold and wait means keeping resources while requesting more. (Key point: Hold and wait meaning)

3. What must the OS ensure to prevent deadlock?
   A. That at least one of the four conditions never holds, e.g. spooling, request-all-at-start, preemption, ordered requests
   B. That all four conditions hold but processes finish quickly
   C. That only one process runs at a time forever
   D. That every resource is preempted after one second
   Answer: A. Breaking any one condition removes the possibility of deadlock. (Key point: Prevention)

4. Which options recover from a detected deadlock?
   A. Number the resources and restart
   B. Abort deadlocked processes, preempt resources with rollback to checkpoint
   C. Spool the printer and share it
   D. Apply aging to the victim
   Answer: B. Recovery uses process termination, resource preemption and checkpoint rollback. (Key point: Recovery)

5. Which factors help choose the victim?
   A. Alphabetical process name
   B. Size of the screen output
   C. Priority, running time, resources used and resources needed
   D. Number of files on disk
   Answer: C. A victim is chosen to minimise lost work, using priority, run time and resources. (Key point: Victim choice)

## Related in Operating System

- [Necessary conditions; deadlock prevention](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-prevention-necessary-conditions) — Operating System, chapter 7
- [Deadlock conditions; recovery methods](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-resource-conditions-recovery) — Operating System, chapter 7
- [Deadlock; necessary conditions with examples](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-necessary-conditions-examples) — Operating System, chapter 7
- [Deadlock conditions and why all necessary](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-why-necessary) — 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 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

## Related in other subjects

- [Distributed deadlock and recovery](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Adistributed-deadlock-note) — Distributed System, chapter 8, asked 3×
- [Deadlock and Coffman conditions](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acoffman-deadlock) — Embedded System, chapter 6, asked 4×
- [Essential and natural boundary conditions](https://www.bctengineer.com/question.md?key=semester_8%2Ffinite_element_method%3Aessential-natural-boundary-conditions) — Finite Element Method, chapter 2
- [Deadlock and its conditions](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Adeadlock-conditions) — Microprocessor, chapter 6, asked 2×
