What is Deadlock in OS? Conditions, Examples & Prevention
Two processes each hold a resource the other one needs. Neither can move forward. Neither will release what it’s holding until it gets what it’s waiting for.…

Two processes each hold a resource the other one needs. Neither can move forward. Neither will release what it’s holding until it gets what it’s waiting for. Both wait forever.
That’s a deadlock. This guide answers what is deadlock in OS clearly — the exact conditions that cause it, a real example, and the three main strategies operating systems use to handle it.
What is Deadlock in an Operating System?
A deadlock is a state where two or more processes are stuck waiting on each other indefinitely, because each one holds a resource that another process needs to continue.
Think of it as a circular waiting problem. Process A holds Resource 1 and needs Resource 2. Process B holds Resource 2 and needs Resource 1. Neither process will give up what it’s holding. Neither can proceed. The system stays stuck unless something intervenes.
The Four Necessary Conditions for Deadlock
A deadlock can only happen when all four of these conditions are true at the same time. This set is known as the Coffman conditions, and removing even one of them prevents deadlock entirely.
Mutual exclusion. At least one resource must be non-shareable — only one process can use it at a time. If every resource could be shared freely, there’d be nothing to compete over.
Hold and wait. A process is holding at least one resource while simultaneously waiting to acquire additional resources held by other processes.
No preemption. A resource can only be released voluntarily by the process holding it. The operating system can’t forcibly take it back.
Circular wait. A closed chain of processes exists, where each process is waiting for a resource held by the next process in the chain.
All four together create the trap. Break any single one, and the deadlock can’t form.
A Simple Real-World Example
Picture two people at a dinner table with one fork and one knife between them. Person A picks up the fork and waits for the knife. Person B picks up the knife and waits for the fork. Neither will put down what they’re holding. Neither can eat. They’ll wait indefinitely unless one of them gives up their utensil.
In an operating system, replace “fork and knife” with “printer and scanner,” or “database lock and file handle.” The mechanism is identical — two processes, two resources, a circular wait with no way out on its own.
How Operating Systems Handle Deadlock
There are three broad strategies, and each makes a different trade-off between safety and performance.
Deadlock prevention works by structurally eliminating one of the four necessary conditions before it can occur — for example, requiring processes to request all resources they’ll need upfront, which removes the “hold and wait” condition entirely. It’s reliable, but often means less efficient resource use.
Deadlock avoidance allows the system to grant resource requests dynamically, but only after checking whether doing so could lead to an unsafe state. The Banker’s Algorithm is the classic example — it simulates resource allocation ahead of time and denies any request that could result in deadlock.
Deadlock detection and recovery takes a different approach entirely: let deadlocks happen, but detect them using a resource allocation graph, then recover by terminating one or more processes or forcibly preempting resources. This trades a small risk of temporary deadlock for better average system performance.
Most modern operating systems don’t rely on strict prevention for every resource, since it’s too costly. A mix of avoidance for critical resources and detection for the rest is far more common in practice.
Deadlock vs. Starvation — Not the Same Thing
These two get confused often, but they’re different problems. In deadlock, processes are stuck permanently, waiting on each other in a circular chain that never resolves on its own.
In starvation, a process keeps getting skipped over by the scheduler in favor of other processes, but it isn’t stuck waiting on a circular resource chain — it’s just unlucky, repeatedly deprioritized. A process in starvation could theoretically still run eventually. A process in deadlock never will, without outside intervention.
Frequently Asked Questions
What is deadlock in OS, in simple terms?
Deadlock is a situation where two or more processes are stuck waiting for each other indefinitely, because each one holds a resource the other needs, and neither will release it.
What are the four conditions required for deadlock?
Mutual exclusion, hold and wait, no preemption, and circular wait. All four must be present simultaneously for a deadlock to occur.
How is deadlock prevented in an operating system?
By structurally removing one of the four necessary conditions — for example, requiring processes to request all needed resources upfront, which eliminates the hold-and-wait condition.
What’s the difference between deadlock prevention and deadlock avoidance?
Prevention eliminates one of the necessary conditions entirely, so deadlock structurally can’t occur. Avoidance allows dynamic resource allocation but checks each request against a safety algorithm, like the Banker’s Algorithm, before granting it.
Is deadlock the same as starvation?
No. Deadlock means processes are permanently stuck waiting on each other in a circular chain. Starvation means a process keeps getting deprioritized by the scheduler, but isn’t stuck in a circular wait — it could still eventually run.
Final Thoughts
Deadlock happens when four specific conditions — mutual exclusion, hold and wait, no preemption, and circular wait — all hold true at once. Operating systems handle it through prevention, avoidance, or detection and recovery, each trading off safety against performance differently.
If you’re building your fundamentals for a systems or software career, working through concepts like this alongside real project work makes them stick. Check out our web development internship guide for what that combination looks like in practice.
Tagged
More from the journal
Need a website that actually ranks?
We build fast, SEO-engineered websites for founders across India. Let's scope your project.
Get a free strategy call →

