0% found this document useful (0 votes)
18 views7 pages

Deadlock Detection and Recovery From Deadlock

to understand dedlock

Uploaded by

officaladvaith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views7 pages

Deadlock Detection and Recovery From Deadlock

to understand dedlock

Uploaded by

officaladvaith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Deadlock Detection and

Recovery from Deadlock

• What is a deadlock?
• Deadlock Detection
• Deadlock Detection Algorithm
• Deadlock Recovery
What is a Deadlock?

A deadlock is a situation in computing (specifically in concurrent


programming or in operating systems) where two or more processes are
unable to proceed because each is waiting for the other(s) to release a
resource or take an action. This results in a situation where none of the
processes can continue, leading to a standstill or deadlock.
In a deadlock, the following conditions are typically present:
• Mutual Exclusion
• Hold and Wait
• No pre-emption
• Circular Wait
Deadlock Detection
Deadlock detection involves identifying when a deadlock has occurred in the
system. Since deadlock is a dynamic condition, the system must continually
check the current state to determine whether a deadlock has occurred.
Deadlock detection typically involves the following steps:
• Resource Allocation Graph (RAG): A common method to detect
deadlock is to use a Resource Allocation Graph (RAG), which represents
processes and resources in a directed graph.
• Nodes
• Processes are represented by circles (P1, P2, ...).
• Processes are represented by circles (P1, P2, ...).

• 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

• Banker's Algorithm (for static resource


allocation): Though primarily used for deadlock
prevention, it can also be used for detection by
checking if the system remains in a safe state after
allocating resources.
• Wait-for Graph (for dynamic systems): Used for
detecting deadlocks by representing processes and
the resources they are waiting for.
Deadlock Recovery

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.

You might also like