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

# Deadlock conditions; detection with example

Operating System · Chapter 7: Deadlock

- Asked in: 2072 Asoj, 2+4+4 marks
- Video: [Deadlocks Detection](https://www.youtube.com/watch?v=2St4eKZ_VVQ) — TutorialsPoint
- 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-detection-example
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-7

## Question

What is deadlock? Explain the essential condition for deadlock. How do you detect deadlock? Explain 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.

## Answer

#### 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
1. **Mutual exclusion:** resources are non-sharable.
2. **Hold and wait:** a process holds a resource while waiting for another.
3. **No preemption:** resources are released only voluntarily.
4. **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.

```text
 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.

## Check yourself

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

1. In a RAG, what does P -> R mean?
   A. P is requesting R
   B. R is allocated to P
   C. P releases R
   D. R requests P
   Answer: A. R -> P is an assignment edge. (Key point: RAG edges)

2. When does a cycle mean deadlock?
   A. Always with multiple instances
   B. Never
   C. When every resource has a single instance
   D. Only with preemption
   Answer: C. With multiple instances use the matrix method. (Key point: Cycle meaning)

3. How does the matrix method start?
   A. Work = 0 and all marked unfinished
   B. Work = Available and processes with zero allocation are marked finished
   C. Work = Allocation sum
   D. Choose the largest Request
   Answer: B. Then repeatedly pick a process with Request <= Work. (Key point: Matrix start)

4. P1 holds A requests B; P2 holds B requests A; Available (0,0). Result?
   A. P1 finishes first
   B. P2 finishes first
   C. No deadlock
   D. Both deadlocked since neither request <= Work
   Answer: D. No process can be marked. (Key point: Example result)

## Related in Operating System

- [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 detection with examples](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Adeadlock-detection-examples) — 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; 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; 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
- [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

## Related in other subjects

- [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 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×
- [Back-face detection algorithm](https://www.bctengineer.com/question.md?key=semester_5%2Fcomputer_graphics%3Aback-face-detection-method) — Computer Graphics, chapter 7, asked 8×
