The Wayback Machine - https://web.archive.org/web/20240930235827/https://www.geeksforgeeks.org/deadlock-detection-recovery/
Open In App

Deadlock Detection And Recovery

Last Updated : 18 Jul, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Deadlock Detection and Recovery is the mechanism of detecting and resolving deadlocks in an operating system. In operating systems, deadlock recovery is important to keep everything running smoothly. A deadlock occurs when two or more processes are blocked, waiting for each other to release the resources they need.

Detection methods help identify when this happens, and recovery techniques are used to resolve these issues and restore system functionality. This ensures that computers and devices can continue working without interruptions caused by deadlock situations. This can lead to a system-wide stall, where no process can make progress.

What is Deadlock?

A deadlock is a situation where two or more processes wait for an event to happen that would never occur. In other words, Deadlock is a situation in computing where two or more programs or processes get stuck, each waiting for the other to release resources, so none of them can proceed. It’s like a traffic jam at an intersection where no car can move because each one is blocking the others.

Approaches to Deadlock Detection and Recovery

  • Prevention: The operating system takes steps to prevent deadlocks from occurring by ensuring that the system is always in a safe state, where deadlocks cannot occur. This is achieved through resource allocation algorithms such as the Banker’s Algorithm.
  • Detection and Recovery: If deadlocks do occur, the operating system must detect and resolve them. Deadlock detection algorithms, such as the Wait-For Graph, are used to identify deadlocks, and recovery algorithms, such as the Rollback and Abort algorithm, are used to resolve them. The recovery algorithm releases the resources held by one or more processes, allowing the system to continue to make progress.

Difference Between Prevention and Detection/Recovery

Prevention aims to avoid deadlocks altogether by carefully managing resource allocation, while detection and recovery aim to identify and resolve deadlocks that have already occurred.

Deadlock detection and recovery is an important aspect of operating system design and management, as it affects the stability and performance of the system. The choice of deadlock detection and recovery approach depends on the specific requirements of the system and the trade-offs between performance, complexity, and risk tolerance. The operating system must balance these factors to ensure that deadlocks are effectively detected and resolved.

In the previous article, we discussed Deadlock Prevention and Avoidance. In this article, the Deadlock Detection and Recovery technique to handle deadlock is discussed. 

Deadlock Detection

1. If Resources Have a Single Instance

In this case for Deadlock detection, we can run an algorithm to check for the cycle in the Resource Allocation Graph. The presence of a cycle in the graph is a sufficient condition for deadlock. 

Single instance resource

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 the cycle is necessary but not a sufficient condition for deadlock detection, in this case, the system may or may not be in deadlock varies according to different situations.

3. Wait-For Graph Algorithm

The Wait-For Graph Algorithm is a deadlock detection algorithm used to detect deadlocks in a system where resources can have multiple instances. The algorithm works by constructing a Wait-For Graph, which is a directed graph that represents the dependencies between processes and resources.

Deadlock Recovery

A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is a time and space-consuming process. Real-time operating systems use Deadlock recovery. 

  • Killing The Process: Killing all the processes involved in the deadlock. Killing process one by one. After killing each process check for deadlock again and keep repeating the process till the system recovers from deadlock. Killing all the processes one by one helps a system to break circular wait conditions.
  • Resource Preemption: Resources are preempted from the processes involved in the deadlock, and preempted resources are allocated to other processes so that there is a possibility of recovering the system from the deadlock. In this case, the system goes into starvation.
  • Concurrency Control: Concurrency control mechanisms are used to prevent data inconsistencies in systems with multiple concurrent processes. These mechanisms ensure that concurrent processes do not access the same data at the same time, which can lead to inconsistencies and errors. Deadlocks can occur in concurrent systems when two or more processes are blocked, waiting for each other to release the resources they need. This can result in a system-wide stall, where no process can make progress. Concurrency control mechanisms can help prevent deadlocks by managing access to shared resources and ensuring that concurrent processes do not interfere with each other.

Advantages of Deadlock Detection and Recovery

  • Improved System Stability: Deadlocks can cause system-wide stalls, and detecting and resolving deadlocks can help to improve the stability of the system.
  • Better Resource Utilization: By detecting and resolving deadlocks, the operating system can ensure that resources are efficiently utilized and that the system remains responsive to user requests.
  • Better System Design: Deadlock detection and recovery algorithms can provide insight into the behavior of the system and the relationships between processes and resources, helping to inform and improve the design of the system.

Disadvantages of Deadlock Detection and Recovery

  • Performance Overhead: Deadlock detection and recovery algorithms can introduce a significant overhead in terms of performance, as the system must regularly check for deadlocks and take appropriate action to resolve them.
  • Complexity: Deadlock detection and recovery algorithms can be complex to implement, especially if they use advanced techniques such as the Resource Allocation Graph or Timestamping.
  • False Positives and Negatives: Deadlock detection algorithms are not perfect and may produce false positives or negatives, indicating the presence of deadlocks when they do not exist or failing to detect deadlocks that do exist.
  • Risk of Data Loss: In some cases, recovery algorithms may require rolling back the state of one or more processes, leading to data loss or corruption.

Overall, the choice of deadlock detection and recovery approach depends on the specific requirements of the system, the trade-offs between performance, complexity, and accuracy, and the risk tolerance of the system. The operating system must balance these factors to ensure that deadlocks are effectively detected and resolved.

Conclusion

Detecting and recovering from deadlocks is crucial for maintaining a smoothly running system. Deadlock detection identifies situations where processes are stuck waiting for each other, and recovery methods help resolve these issues to keep the system operational. By effectively managing deadlocks, we ensure that the system remains efficient and reliable.

Frequently Asked Questions on Deadlock Detection And Recovery – FAQs

How to detect a deadlock?

The main way to find and fix deadlocks is with detection algorithms. There are different types, like Wait-For Graphs, Banker’s Algorithm, Resource Allocation Graphs, Combined Detection Algorithms, and Timeouts. These tools help computers stay running smoothly by catching and fixing deadlocks quickly.

What are the methods used to recover from the deadlock?

There are four methods of deadlock recovery: process termination, resource pre-emption, priority inversion, and rollback.

What is the principle of deadlock?

Deadlock in operating systems happens when two or more processes can’t move forward because each one is waiting for a resource that another process has.



Previous Article
Next Article

Similar Reads

Difference between Deadlock Prevention and Deadlock Avoidance
Deadlock is a condition where a set of processes becomes stuck and waits infinitely for the resources which are hold by other processes. To handle these types of problems, we use two strategies - Deadlock Prevention and Deadlock Avoidance. Deadlock Prevention means blocking one of the conditions necessary for deadlock while deadlock avoidance refer
4 min read
Recovery from Deadlock in Operating System
In today's world of computer systems and multitasking environments, deadlock is an undesirable situation that can bring operations to a halt. When multiple processes compete for exclusive access to resources and end up in a circular waiting pattern, a deadlock occurs. To maintain the smooth functioning of an operating system, it is crucial to imple
8 min read
Chandy-Misra-Haas's Distributed Deadlock Detection Algorithm
Chandy-Misra-Haas's distributed deadlock detection algorithm is an edge chasing algorithm to detect deadlock in distributed systems. In edge chasing algorithm, a special message called probe is used in deadlock detection. A probe is a triplet (i, j, k) which denotes that process Pi has initiated the deadlock detection and the message is being sent
4 min read
Deadlock Detection Algorithm in Operating System
In operating systems, managing resources like memory, files, and processors is very important. Sometimes, processes (or programs) get stuck waiting for each other to release resources, leading to a situation called a deadlock. To handle deadlocks, operating systems use special methods called deadlock detection algorithms. These algorithms help iden
7 min read
Introduction to TimeStamp and Deadlock Prevention Schemes in DBMS
Deadlock occurs when each transaction T in a schedule of two or more transactions waiting for some item locked by some other transaction T' in the set. Thus, both end up in a deadlock situation, waiting for the other to release the lock on the item. Deadlocks are a common problem and we have introduced the problem while solving the Concurrency Cont
7 min read
Relation Between Number of Processes and Number of Resources to Prevent Deadlock
A set of blocked processes where each process is holding some resource and waiting to acquire some other resource held by another process in the set. This situation is called deadlock in the operating system. Deadlock can be prevented if the number of resource instances in a system is significantly larger than the number of processes asking for a r
3 min read
Deadlock Prevention And Avoidance
When two or more processes try to access the critical section at the same time and they fail to access simultaneously or stuck while accessing the critical section then this condition is known as Deadlock. Deadlock prevention and avoidance are strategies used in computer systems to ensure that different processes can run smoothly without getting st
6 min read
Deadlock, Starvation, and Livelock
Prerequisite - Deadlock and Starvation  Livelock occurs when two or more processes continually repeat the same interaction in response to changes in the other processes without doing any useful work. These processes are not in the waiting state, and they are running concurrently. This is different from a deadlock because in a deadlock all processes
6 min read
Difference between Deadlock and Starvation in OS
Deadlock is a condition wherein all the processes are holding one resource each and are waiting for another process to release another resource. Starvation is a state that prevents lower-precedence processes from getting the resources. Starvation arises when procedures with critical importance keep on utilizing the resources frequently. Therefore,
7 min read
Difference Between Recovery ROM and Fastboot ROM
ROM stands for read-only memory. It is the storage type built into a device during manufacturing. There is various types of ROM available, Recovery ROM and Fastboot ROM are two of them. Both Recovery ROM and Fastboot ROM can be flashed. What is Recovery ROM?ROM that can be easily flashed by recovery or mobile is called Recovery ROM. The file extens
4 min read
Operating Systems | Deadlock | Question 1
Suppose n processes, P1, â€Ķ. Pn share m identical resource units, which can be reserved and released one at a time. The maximum resource requirement of process Pi is Si, where Si > 0. Which one of the following is a sufficient condition for ensuring that deadlock does not occur? (A) A (B) B (C) C (D) D Answer: (C) Explanation: See Question 4 on foll
1 min read
Operating Systems | Deadlock | Question 2
Consider the following snapshot of a system running n processes. Process i is holding Xi instances of a resource R, 1 <= i <= n. currently, all instances of R are occupied. Further, for all i, process i has placed a request for an additional Yi instances while holding the Xi instances it already has. There are exactly two processes p and q su
1 min read
Deadlock Ignorance in Operating System
In this article we will study in brief about what is Deadlock followed by Deadlock Ignorance in Operating System. What is Deadlock? If each process in the set of processes is waiting for an event that only another process in the set can cause it is actually referred as called Deadlock. In other words, one event which has to happen by one process wi
5 min read
Deadlock System model
Overview :A deadlock occurs when a set of processes is stalled because each process is holding a resource and waiting for another process to acquire another resource. In the diagram below, for example, Process 1 is holding Resource 1 while Process 2 acquires Resource 2, and Process 2 is waiting for Resource 1. System Model : For the purposes of dea
8 min read
Conditions for Deadlock in Operating System
A deadlock is a situation where a set of processes is blocked because each process is holding a resource and waiting for another resource acquired by some other process. In this article, we will discuss what is deadlock and the necessary conditions required for deadlock. What is Deadlock?Deadlock is a situation in computing where two or more proces
8 min read
Introduction of Deadlock in Operating System
A deadlock is a situation where a set of processes is blocked because each process is holding a resource and waiting for another resource acquired by some other process. In this article, we will discuss deadlock, its necessary conditions, etc. in detail. What is Deadlock?Deadlock is a situation in computing where two or more processes are unable to
11 min read
Huang's Termination detection algorithm
Huang's algorithm is an algorithm for detecting termination in a distributed system. The algorithm was proposed by Shing-Tsaan Huang in 1989 in the Journal of Computers. In a distributed system, a process is either in an active state or in an idle state at any given point of time. Termination occurs when all of the processes becomes idle and there
4 min read
Hardware Synchronization Algorithms : Unlock and Lock, Test and Set, Swap
Process Synchronization problems occur when two processes running concurrently share the same data or same variable. The value of that variable may not be updated correctly before its being used by a second process. Such a condition is known as Race Around Condition. There are a software as well as hardware solutions to this problem. In this articl
5 min read
Difference between Multiprogramming, multitasking, multithreading and multiprocessing
Multiprogramming - Multiprogramming is known as keeping multiple programs in the main memory at the same time ready for execution.Multiprocessing - A computer using more than one CPU at a time.Multitasking - Multitasking is nothing but multiprogramming with a Round-robin scheduling algorithm.Multithreading is an extension of multitasking.FeatureMul
11 min read
Process-Based and Thread-Based Multitasking
Multitasking operating system is an operating system that gives you the perception of two or more tasks/jobs/processes running simultaneously. It does this by dividing system resources amongst these tasks/jobs/processes and switching between the tasks/jobs/processes while they are executing over and over again. The CPU processes only one task at a
2 min read
Difference between DOS and Windows
DOS and Windows square measure the various varieties of Operating Systems. DOS stands for Disk Operating System. It is a smaller amount probably employed in the current state of affairs whereas windows may be a wide used in operation system. It consumes less memory and power than windows. Features of DOS: Command Line Interface: DOS is primarily a
4 min read
Allocating kernel memory (buddy system and slab system)
Prerequisite - Buddy System Introduction: Allocating kernel memory is a critical task in operating system design, as the kernel needs to manage memory efficiently and effectively to ensure optimal system performance. Two common methods for allocating kernel memory are the buddy system and the slab system. The buddy system is a memory allocation alg
9 min read
Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
Prerequisite - CPU Scheduling Priority Scheduling : In priority scheduling, each process has a priority which is an integer value assigned to it. The smallest integer is considered as the highest priority and the largest integer is considered as the lowest priority. The process with the highest priority gets the CPU first. In rare systems, the larg
4 min read
Completely fair Scheduler (CFS) and Brain Fuck Scheduler (BFS)
Prerequisite - CPU Scheduling Completely fair Scheduler (CFS) and Brain Fuck Scheduler (BFS) are two different process schedulers currently used in Linux. Process Scheduling - As any program is loaded as process in RAM and then CPU executes the process according to the priority of the process. 1. Completely fair Scheduler (CFS) : It is based on Rot
4 min read
Cvent Interview Experience (On campus for Internship and Full Time)
Technical attitude test(Round 1) This round consisted of 30 aptitude questions based on general aptitude and computer science fundamental subjects like operating system, dbms, c/c++, sql, computer networks. Around 300 students sat for this test and 41 students were shortlisted for the next coding round. Coding round(Round 2) This round consisted of
4 min read
Difference between Traditional and Reactive Computer System
1. Traditional Computer System: Traditional Computer System takes the input from the user and computes the output as the function of the input. It basically computes functions of the input. A traditional computer system is one in which the computer is in control of the sequence of operations. This type of system is typically used for batch processi
5 min read
Difference between CD and DVD
CD stands for Compact Disc was the primary step towards the thought of digital coding of the info. It uses a novel methodology of coding within which a 14-bit code indicates a computer memory unit and this coding technique conjointly helps in error detection. it had been an acceptable replacement for the memory device because it offered the low-pri
3 min read
Difference between Virtual memory and Cache memory
Cache Memory: Cache memory increases the accessing speed of CPU. It is not a technique but a memory unit i.e a storage device. In cache memory, recently used data is copied. Whenever the program is ready to be executed, it is fetched from main memory and then copied to the cache memory. But, if its copy is already present in the cache memory then t
2 min read
Difference between Supercomputer and Mainframe Computer
Prerequisite - Generations of Computer Supercomputers: Supercomputers are the largest in size and the most costly computers in the world. Seymour Cray invents the Supercomputer. Supercomputers are used for large and complex mathematical computations. Supercomputer's speed is more than Mainframe computers so they can execute billions of instructions
2 min read
Difference between Mainframe and Minicomputer
Prerequisite - Classification of Computers Mainframe Computers and Minicomputers are the categories of a laptop wherever mainframe computers give rather more options than minicomputer and high capability for memory and process speed. At the beginning, Mainframe Computers were made to produce responsibility for the dealing process and are primarily
2 min read
Article Tags :