What is deadlock in an operating system? Explain its necessary conditions and methods of handling deadlocks.

What is deadlock in an operating system? Explain its necessary conditions and methods of handling deadlocks.

From the Combined Bank Assistant Programmer (CSE) October 2026 – Written (BIBM) exam, question 2 of 21.

Answers (1)

Deadlock is a state where a set of processes are each waiting for a resource held by another process in the set, so none of them can ever proceed. Example: P1 holds the printer and waits for the scanner; P2 holds the scanner and waits for the printer.

Necessary (Coffman) conditions — all four must hold at once:

  1. Mutual exclusion: a resource can be held by only one process at a time.
  2. Hold and wait: a process holds at least one resource while waiting for others.
  3. No preemption: a resource cannot be taken away; it is released only voluntarily.
  4. Circular wait: a cycle P1 → P2 → … → Pn → P1, each waiting for the next one’s resource.

Methods of handling

  • Prevention: break one condition by design — e.g. request all resources at once (no hold-and-wait), allow preemption, or number resources and always request them in increasing order (no circular wait).
  • Avoidance: grant a request only if the system stays in a safe state, using advance knowledge of maximum needs — the Banker’s algorithm.
  • Detection and recovery: let deadlocks happen, detect cycles in a wait-for / resource-allocation graph periodically, then recover by terminating processes or preempting resources (rolling a victim back).
  • Ignoring (Ostrich approach): assume deadlocks are rare and reboot if one occurs; used by most general-purpose OSs such as Windows and Linux.

— rhs

More from this paper