In the previous post, we have discussed Deadlock Prevention and Avoidance. In this post, Deadlock Detection and Recovery technique to handle deadlock is discussed.
1. If resources have single instance:
In this case for Deadlock detection we can run an algorithm to check for cycle in the Resource Allocation Graph. Presence of cycle in the graph is the sufficient condition for deadlock.
In the above diagram, resource 1 and resource 2 have single instances. There is a cycle R1–>P1–>R2–>P2. So Deadlock is Confirmed.
2. If there are multiple instances of resources:
Detection of cycle is necessary but not sufficient condition for deadlock detection, in this case system may or may not be in deadlock varies according to different situations.
Traditional operating system such as Windows doesn’t deal with deadlock recovery as it is time and space consuming process. Real time operating systems use Deadlock recovery.
1. Killing the process.
killing all the process involved in deadlock. Killing process one by one. After killing each process check for deadlock again keep repeating process till system recover from deadlock.
2. Resource Preemption
Resources are preempted from the processes involved in deadlock, preempted resources are allocated to other processes, so that their is a possibility of recovering the system from deadlock. In this case system go into starvation.
See Quiz on Deadlock.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Operating System | Deadlock detection algorithm
- Operating System | Resource Allocation Graph (RAG)
- Program for Banker's Algorithm | Set 1 (Safety Algorithm)
- Zombie Processes and their Prevention
- What exactly Spooling is all about?
- Operating System | Banker's Algorithm
- Operating System | Paging
- Operating System | Thread
- Operating System | Memory Management |Partition Allocation Method
- Process Synchronization | Monitors
- Deadlock Prevention And Avoidance
- Operating System | Process Management | Deadlock Introduction
- Operating System | Process Synchronization | Introduction
- Commonly Asked Operating Systems Interview Questions | Set 1
- Operating Systems | Set 16