Deadlock
DEAD LOCK SCENARIO
Every process needs some resources to complete its
execution. However, the resource is granted in a
sequential order.
[Link] process requests for some resource
[Link] grant the resource if it is available otherwise
let the process waits.
[Link] process uses it and release on the completion .
.
What is deadlock?
Deadlock is a state in which two or more processes are
unable to proceed because each is waiting for a resource
that the other holds, resulting in a cycle of dependencies,
Conditions for Deadlock
For deadlock to occur, four necessary conditions
must hold simultaneously. These conditions are
often referred to as the Coffman conditions
Condition for Deadlock
•Mutual Exclusion:At least one resource must be held in a non-shareable mode, meaning only
one process can use it at a time. Example: A printer can only be used by one process at a time.
•Hold and Wait: A process holding at least one resource is waiting to acquire additional
resources that are currently being held by other processes. Example: Process A holds a printer
and waits for a scanner, while Process B holds a scanner and waits for the printer.
•No Preemption: Resources cannot be forcibly taken away from processes holding them. A
process must release the resource voluntarily when it is no longer needed. Example: If
Process A is holding a printer and is waiting for a scanner, the system cannot force Process A
to give up the printer.
•Circular Wait: A set of processes exist such that each process in the set is waiting for a
resource that another process in the set holds, forming a cycle of dependencies. Example:
Process A waits for Process Bs resource, Process B waits for Process Cs resource, and
Process C waits for Process As resource, forming a circular chain.
Strategies for handling Deadlock
[Link] prevention
Deadlock happens only when Mutual Exclusion, hold and wait, No preemption and
circular wait holds simultaneously. If it is possible to violate one of the four conditions
at any time then the deadlock can never occur in the system
3. Deadlock avoidance
In deadlock avoidance, the operating system checks whether the system is in safe
state or in unsafe state at every step which the operating system performs. The
process continues until the system is in safe state. Once the system moves to unsafe
state, the OS has to backtrack one step.
[Link] detection and recovery
This approach let the processes fall in deadlock and then periodically check whether
deadlock occur in the system or not. If it occurs then it applies some of the recovery
methods to the system to get rid of deadlock