Deadlock
Deadlock
A set of Processes is deadlock if each process in the set is waiting for an event that only
another process in the set can cause.
Deadlock are a set of blocked processes each holding a resource and waiting to acquire a
resource held by another process.
Preemptable and non-preemptable resource
• Preemptable:- Preemptive resources are those which can be taken
away from a process without causing any ill effects to the process.
Example: Memory
Non-preemptable:- Non pre-emptive resources are those which cannot
be taken away from the process without causing any ill effects.
Example:- CD-ROM (CD recorder), Printer
Condition that lead to deadlock
1 Mutual exclusion
• Each resource is either currently assigned to exactly one process or is
available.
2. Hold and Wait
• Process currently holding resources granted earlier can request more
resources.
3. No Preemption
• Previously granted resources cannot be forcibly taken away from Process.
4. Circular Wait
• There must be a circular chain of 2 or more processes. Each process is
waiting for resource that is held by next member of the chain.
All four of these conditions must be present for a deadlock to occur.
Deadlock ignorance
- When storm approach, an ostrich puts his head in the sand (ground)
and pretend(imagine) that there is no problem at all.
- ignore the deadlock and pretend that deadlock never occur.
• Reasonable if
- deadlocks occur very rarely
- difficult to detect
- cost of prevention is high
- Unix and windows takes this approach
Deadlock Recovery
1. Recovery through pre-emption
In this method resources are temporarily taken away from its current
owner and give it to another process.
The ability to take a resource away from a process, have another
process use it, and then give it back without the process noticing
it is highly dependent on the nature of the resource.
Recovering this way is frequently difficult or impossible.
Deadlock Recovery
• 2. Recovery through rollback
• - PCB (Process Control Block) and resource state are periodically saved
at "checkpoint".
• - When deadlock is detected, rollback the preempted process up to
the previous safe state before it acquired that resource.
• Discard the resource manipulation that occurred after that
checkpoint.
• -Start the process after it is determined it can run again.
3. Recovery through killing processes