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

# Deadlock; necessary conditions with examples

Operating System · Chapter 7: Deadlock

- Asked in: 2068 Magh, 4+4 marks; year not given
- Video: [L-4.1: DEADLOCK concept | Example | Necessary condition | Operating System](https://www.youtube.com/watch?v=rWFH6PLOIEI) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/deadlock-necessary-conditions-examples
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

What is deadlock? Discuss the necessary conditions for deadlock with examples.

## Short answer

Deadlock occurs when processes wait circularly for resources. Four necessary conditions: mutual exclusion, hold and wait, no preemption, and circular wait. Example: Process P holds printer and wants scanner; Q holds scanner and wants printer.

## Answer

#### Deadlock
A set of processes is in **deadlock** if each process in the set is waiting for an event (usually the release of a resource) that only another process in the set can cause. None of them can proceed, so all wait forever.

**Example:** process P holds a printer and requests a scanner; process Q holds the scanner and requests the printer. Neither can continue.

#### Necessary (Coffman) conditions
All four must hold together for deadlock.

1. **Mutual exclusion:** a resource can be used by only one process at a time. Example: a printer; if P is printing, Q must wait.
2. **Hold and wait:** a process holding at least one resource is waiting to acquire more resources held by others. Example: P holds the printer and waits for the scanner.
3. **No preemption:** a resource cannot be forcibly taken from a process; it is released only voluntarily. Example: the printer cannot be taken from P mid-job.
4. **Circular wait:** there is a circular chain of processes, each waiting for a resource held by the next.

```text
  P1 --waits for--> R2
  ^                  |
 held by          held by
  |                  v
  R1 <--waits for-- P2
```

Here P1 holds R1 and wants R2, while P2 holds R2 and wants R1: a cycle in the resource allocation graph.

Removing any one condition prevents deadlock.

## Check yourself

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

1. What is deadlock?
   A. Each process in a set waits for an event only another process in the set can cause
   B. A process runs forever in a loop
   C. Memory is exhausted
   D. A process is terminated
   Answer: A. None of the processes can proceed, so all wait forever. (Key point: Definition)

2. Which set lists all necessary conditions?
   A. Mutual exclusion, starvation, aging, circular wait
   B. Mutual exclusion, hold and wait, no preemption, circular wait
   C. Hold and wait, preemption, spooling, circular wait
   D. Mutual exclusion, paging, no preemption, hold and wait
   Answer: B. All four must hold together. (Key point: Four conditions)

3. In the printer-scanner example, what shows hold and wait?
   A. P releases the printer before asking
   B. P and Q share the printer
   C. P holds the printer while waiting for the scanner
   D. OS takes the printer from P
   Answer: C. P holds one resource while requesting another. (Key point: Hold and wait example)

4. What happens if any one condition is removed?
   A. Deadlock becomes more likely
   B. Only circular wait matters
   C. Nothing changes
   D. Deadlock cannot occur
   Answer: D. All four are necessary, so breaking one prevents deadlock. (Key point: Removing a condition)

## Related in Operating System

- [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
- [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, detection, action](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-conditions-detection-recovery-action) — 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 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
- [Deadlock conditions; Banker's with 4 processes](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afour-conditions-banker-p1-p4) — 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×
- [Need of transaction; phantom deadlock](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Atransaction-deadlock-phantom) — Distributed System, chapter 8
