Deadlocks Flashcards
deadlock
A set of processes is deadlocked if:
- Each process in the set waiting for an event
- That event can be caused only by another
process
livelock
operations are being executed but no progress is made
conditions for resource deadlocks
- mutual exclusion
- hold and wait
- no preemption
- circular wait condition
mutual exclusion
each resource is assigned to at most one process
hold and wait
processes can request a resource when holding another one
no preemption
resources cannot be taken away from a process
circular wait condition
chain of two or more processes must be waiting for a resource held by next process in the chain
deadlock handling
- ignore the problem
- deadlock detection
- deadlock avoidance
- deadlock prevention
ignore the problem
no action taken
the OS doesn’t handle deadlocks, it is up to the programmer, i.e. manual
- Also known as the ostrich algorithm
- Cost-effective solution to deadlocks
- Assumes deadlocks are rare
- Assumes cost of handling deadlocks is high
- Assumes effects of deadlocks are tolerable
- Simplest solution to manage system resources, i.e., process table, inode table, swap space, etc.
deadlock detection
detect deadlock and perform recovery actions
algorithm for detection + algorithm/mechanism for recovery
- Detection
- Check for cycles in the resource allocation graph
- Track progress and time out
- Explicit detection (e.g., OOM)
- Useful in practice when simple and efficient detection mechanisms (e.g., progress tracking or explicit detection) along with recovery actions are available
deadlock avoidance
carefully allocate resources to avoid deadlocks
requires additional information about resources a process might need during its lifeitme
deadlock prevention
structurally prevent any of the deadlock conditions
provides a method for ensuring at least one of the 4 conditions cannot hold
recovery from a deadlock
force preemption
checkpoint-rollback
killing the offending process
killing the offending process
- abort all deadlocked processes
⇒ expensive, computations done so far have to be done again - abort one process at a time until the deadlock cycle is eliminated
⇒ considerable overhead, after each process is aborted a deadlock check algorithm is invoked
abort processes whose termination will incur the minimum cost; think about:- what the priority of the process is
- how long the process has computed how much longer the process will compute completing its designated task
- resources the process is using and needs to use
- how many processes will be terminated
- whether the process is interactive or batch
issues with aborting a process
it was modifying a file→ it leaves a file in an incorrect state