Deadlock Detection and Recovery From Deadlock
Deadlock Detection and Recovery From Deadlock
• What is a deadlock?
• Deadlock Detection
• Deadlock Detection Algorithm
• Deadlock Recovery
What is a Deadlock?
• Edges:
• Request edges: From a process to a resource, indicating that the
process is requesting that resource.
• Assignment edges: From a resource to a process, indicating
that the resource is assigned to that process.
• Cycle Detection: The key to detecting deadlock in a resource
allocation graph is cycle detection. If there is a cycle in the
graph (i.e., a set of processes waiting on each other in a
circular chain), then a deadlock has occurred.
• Cycle in RAG: If a process is waiting for a resource that is held by
another process, and that second process is waiting for a resource
held by the first process, a cycle is formed, signaling deadlock.
Deadlock Detection Algorithm
Once a deadlock has been detected, the system needs to take actions to
recover from it. Recovery aims to break the deadlock and restore the
system to a normal operational state.
Common Methods of Recovery:
• Process Termination: One approach is to terminate one or
more processes involved in the deadlock. There are several
ways to decide which processes to terminate:
• Resource Preemption: Another recovery technique is resource
preemption, where resources are forcefully taken away from one
process and given to another to break the circular wait. This
involves:
• Rollback and Checkpointing:
• Rollback: When a process is rolled back, it is restarted from a
previous state, undoing its actions that led to the deadlock. This
method requires a mechanism for saving the state of processes at
certain intervals, called checkpointing.
• Checkpointing: The system periodically saves the state of
processes to a stable storage. If a deadlock occurs, processes can
be rolled back to their last checkpointed state, potentially
breaking the deadlock
• Timeouts:
• Some systems use timeouts to automatically detect if a process
is taking too long to acquire a resource. If a process waits for a
resource longer than a predefined period, it is considered to be in
a deadlock state, and it can be terminated or rolled back.