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

# Necessary conditions; deadlock prevention

Operating System · Chapter 7: Deadlock

- Asked in: year not given
- Video: [Deadlock Prevention in Operating System | Methods & Conditions Explained#operatingsystem](https://www.youtube.com/watch?v=y1g7wa9aT3c) — T V Nagaraju Technical
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/deadlock-prevention-necessary-conditions
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

What are the necessary conditions for deadlock? How can deadlock be prevented?

## Short answer

The four necessary conditions for deadlock are mutual exclusion, hold and wait, no preemption, and circular wait. Prevention ensures at least one condition never holds: spooling for mutual exclusion, requesting all resources initially for hold and wait, allowing preemption for no preemption, and imposing a total ordering on resource requests for circular wait.

## Answer

#### Necessary conditions for deadlock
1. **Mutual exclusion:** a non-sharable resource is held by one process at a time.
2. **Hold and wait:** a process holds resources while waiting for more.
3. **No preemption:** resources cannot be forcibly removed from a process.
4. **Circular wait:** a cycle of processes, each waiting for the next one's resource.

#### Deadlock prevention
Prevention designs the system so that at least one of the conditions can never occur.

| Condition attacked | Technique | Drawback |
|---|---|---|
| Mutual exclusion | Make resources sharable, spool devices like printers | Not possible for all resources |
| Hold and wait | Request all resources before execution begins, or release all before a new request | Low utilisation, starvation, future needs unknown |
| No preemption | If a request is denied, process releases all its held resources; or the OS preempts them | Only for resources whose state can be saved |
| Circular wait | Number resources; allow requests only in increasing order | Hard to find a good ordering for every program |

**Example of circular wait prevention:** resources numbered Scanner = 1, Printer = 2. A process holding the printer cannot ask for the scanner; it must request the scanner first. Hence P and Q cannot wait on each other in a cycle.

## 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 does deadlock prevention aim to do?
   A. Detect cycles after they form and kill a process
   B. Make sure at least one of the four necessary conditions can never hold
   C. Grant a request only if the resulting state is safe
   D. Let all four conditions hold but schedule processes fairly
   Answer: B. Prevention structurally breaks at least one necessary condition, so deadlock cannot occur. (Key point: Prevention principle)

3. How can hold and wait be prevented, and what is the drawback?
   A. Request resources in numerical order; hard to find an ordering
   B. Spool the device; not all resources can be spooled
   C. Preempt resources; only works for printers
   D. Request all resources before starting; low utilisation and need to know needs in advance
   Answer: D. Requiring all resources up front breaks hold and wait but wastes resources and needs advance knowledge. (Key point: Hold and wait prevention)

4. Scanner = 1, Printer = 2. A process holding the printer needs the scanner. What must it do?
   A. Wait for the scanner while holding the printer
   B. Not request it while holding the printer; it should have requested the scanner first
   C. Release the scanner it does not hold
   D. Kill the other process
   Answer: B. Requests must be in increasing numerical order, so no cycle can form. (Key point: Circular wait example)

## Related in Operating System

- [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
- [Four deadlock conditions; prevention, recovery](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-prevention-recovery) — 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, detection, action](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-detection-recovery-action) — 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

- [Deadlock and Coffman conditions](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Acoffman-deadlock) — Embedded System, chapter 6, asked 4×
- [Deadlock and its conditions](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Adeadlock-conditions) — Microprocessor, chapter 6, asked 2×
- [Slab prevented from uplifting, 3.6x4.2 m](https://www.bctengineer.com/question.md?key=semester_7%2Fdesign_of_rcc_structure%3Aslab-prevented-from-uplifting-3-6x4) — Design of RCC Structure, chapter 9
- [Need of transaction; phantom deadlock](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Atransaction-deadlock-phantom) — Distributed System, chapter 8
