What is deadlock?

Why Interviewers Ask This

Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Operating Systems development. It reveals whether you understand the building blocks that more complex concepts rely on.

Answer

A deadlock is a situation where two or more processes are permanently blocked, each waiting for a resource held by another — a circular waiting dependency from which no process can escape. Classic example: Process A holds Lock 1, wants Lock 2. Process B holds Lock 2, wants Lock 1. Neither can proceed — deadlock! Four necessary conditions (Coffman, 1971): ALL four must hold simultaneously for deadlock to occur: (1) Mutual exclusion: at least one resource is non-shareable — only one process can use it at a time; (2) Hold and wait: a process holds at least one resource while waiting to acquire additional resources held by others; (3) No preemption: resources can only be released voluntarily by the holding process — cannot be forcibly taken; (4) Circular wait: a set {P0, P1,...,Pn} where P0 waits for P1, P1 waits for P2,..., Pn waits for P0. Deadlock handling strategies: Prevention (eliminate one of the four conditions); Avoidance (dynamically check if granting a resource leads to deadlock — Banker's Algorithm); Detection and Recovery (allow deadlock, detect it, recover by killing a process or preempting resources); Ignorance (Ostrich algorithm — ignore deadlock; restart system when needed — used by Windows and many Unix systems in practice). Resource allocation graph: represents processes and resources as nodes, requests and holdings as directed edges. A cycle in this graph indicates deadlock (when resources have single instances).

Pro Tip

If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.