Deadlock Handling in Operating Systems
Deadlock Handling in Operating Systems
In an operating system, deadlock occurs when a set of processes are blocked because each
process is holding a resource and waiting for another resource held by another process. To
handle deadlocks, there are several strategies, and they can be categorized into four main types:
1. Deadlock Prevention
2. Deadlock Avoidance
3. Deadlock Detection and Recovery
4. Deadlock Ignorance
1. Deadlock Prevention
Deadlock prevention ensures that the system is designed in such a way that at least one of the
necessary conditions for deadlock (mutual exclusion, hold and wait, no preemption, circular
wait) cannot occur.
Key Methods:
• Eliminate Mutual Exclusion: Some resources (like printers, hard disks) must be
accessed one at a time, so this condition is impossible to fully eliminate. However, where
possible, systems can make resources shareable.
• Eliminate Hold and Wait: Ensure processes do not hold any resources when requesting
additional resources. This can be done in two ways:
o Resource Allocation at Once: Allocate all resources to a process at the
beginning.
o Release Before Requesting: Force the process to release all the resources it holds
before requesting new ones.
• Eliminate No Preemption: If a process holding some resources makes a new request
that cannot be immediately fulfilled, all the resources it holds are preempted and added to
the resource pool, then reallocated.
• Eliminate Circular Wait: Impose an ordering (numbering) on the resource types and
require that each process requests resources in an increasing order of enumeration.
2. Deadlock Avoidance
• Safe State: A state is safe if the system can allocate resources to each process in some
order and still avoid a deadlock.
The operating system uses algorithms like Banker’s to check whether it is safe to allocate
resources to a process at any time. If the allocation leaves the system in an unsafe state, the
system will not grant the resources.
Example:
• Banker’s Algorithm: Each process declares the maximum number of resources it may
need, and the system grants or denies requests based on whether the resulting state would
be "safe."
In deadlock detection, the system allows processes to request resources as needed, but it
periodically checks the system for deadlocks. If a deadlock is detected, the system takes action to
recover from it.
Key Steps:
4. Deadlock Ignorance
Some operating systems, like most implementations of UNIX and Windows, simply ignore the
possibility of deadlock. This is often called the Ostrich Algorithm, where the system assumes
that deadlocks will be rare enough that they can be ignored. In such cases, if deadlocks occur, the
only way to recover might be to restart the system or manually kill processes.
Summary of Methods:
Each method has its advantages and trade-offs, and the choice of which one to use depends on
the system requirements and constraints.