Recovery from Deadlock in Operating System
Last Updated :
11 Jul, 2025
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 implement recovery mechanisms that can break these deadlocks and restore the system's productivity.
What is Recovery from Deadlock in OS?
"Recovery from Deadlock in Operating Systems" refers to the set of techniques and algorithms designed to detect, resolve, or mitigate deadlock situations. These methods ensure that the system can continue processing tasks efficiently without being trapped in an eternal standstill. Let's take a closer look at some of the key strategies employed.
There is no mechanism implemented by the OS to avoid or prevent deadlocks. The system, therefore, assumes that a deadlock will undoubtedly occur. The OS periodically checks the system for any deadlocks in an effort to break them. The OS will use various recovery techniques to restore the system if it encounters any deadlocks. When a Deadlock Detection Algorithm determines that a deadlock has occurred in the system, the system must recover from that deadlock.
What is Deadlock?
In an operating system, a deadlock is a situation where a group of processes is stuck and unable to proceed because each one is waiting for a resource that another process in the group is holding.
Imagine four people at a round table, each with one fork, and they need two forks to eat. If everyone picks up the fork to their left and waits for the fork on their right, no one can eat. They are all stuck, waiting forever. This is a deadlock.
In technical terms, deadlock involves four conditions:
- Mutual Exclusion : Resources cannot be shared; they can only be used by one process at a time.
- Hold and Wait : Processes holding resources can request additional resources.
- No Preemption : Resources cannot be forcibly taken away from processes holding them.
- Circular Wait : A closed chain of processes exists, where each process holds at least one resource needed by the next process in the chain.
Having a deep understanding of deadlock recovery techniques is vital for anyone
Ways of Handling a Deadlock
There are several ways of handling a deadlock, some of which are mentioned below:
1. Process Termination
To eliminate the deadlock, we can simply kill one or more processes. For this, we use two methods:
- Abort all the Deadlocked Processes : Aborting all the processes will certainly break the deadlock but at a great expense. The deadlocked processes may have been computed for a long time, and the result of those partial computations must be discarded and there is a probability of recalculating them later.
- Abort one process at a time until the deadlock is eliminated : Abort one deadlocked process at a time, until the deadlock cycle is eliminated from the system. Due to this method, there may be considerable overhead, because, after aborting each process, we have to run a deadlock detection algorithm to check whether any processes are still deadlocked.
Advantages of Process Termination
- It is a simple method for breaking a deadlock.
- It ensures that the deadlock will be resolved quickly, as all processes involved in the deadlock are terminated simultaneously.
- It frees up resources that were being used by the deadlocked processes , making those resources available for other processes.
Disadvantages of Process Termination
- It can result in the loss of data and other resources that were being used by the terminated processes.
- It may cause further problems in the system if the terminated processes were critical to the system's operation.
- It may result in a waste of resources , as the terminated processes may have already completed a significant amount of work before being terminated.
2. Resource Preemption
To eliminate deadlocks using resource preemption, we preempt some resources from processes and give those resources to other processes. This method will raise three issues:
- Selecting a Victim : We must determine which resources and which processes are to be preempted and also in order to minimize the cost.
- Rollback : We must determine what should be done with the process from which resources are preempted. One simple idea is total rollback. That means aborting the process and restarting it.
- Starvation : In a system, it may happen that the same process is always picked as a victim. As a result, that process will never complete its designated task. This situation is called Starvation and must be avoided. One solution is that a process must be picked as a victim only a finite number of times.
Advantages of Resource Preemption
- It can help in breaking a deadlock without terminating any processes, thus preserving data and resources.
- It is more efficient than process termination as it targets only the resources that are causing the deadlock .
- It can potentially avoid the need for restarting the system.
Disadvantages of Resource Preemption
- It may lead to increased overhead due to the need for determining which resources and processes should be preempted.
- It may cause further problems if the preempted resources were critical to the system's operation.
- It may cause delays in the completion of processes if resources are frequently preempted.
3. Priority Inversion
A technique for breaking deadlocks in real-time systems is called priority inversion. This approach alters the order of the processes to prevent stalemates. A higher priority is given to the process that already has the needed resources, and a lower priority is given to the process that is still awaiting them. The inversion of priorities that can result from this approach can impair system performance and cause performance issues. Additionally, because higher-priority processes may continue to take precedence over lower-priority processes, this approach may starve lower-priority processes of resources.
4. RollBack
In database systems, rolling back is a common technique for breaking deadlocks. When using this technique, the system reverses the transactions of the involved processes to a time before the deadlock. The system must keep a log of all transactions and the system's condition at various points in time in order to use this method. The transactions can then be rolled back to the initial state and executed again by the system. This approach may result in significant delays in the transactions' execution and data loss.
Resource Allocation Graph (RAG) for Deadlock Detection
The resource allocation graph (RAG) is a popular technique for computer system deadlock detection. The RAG is a visual representation of the processes holding the resources and their current state of allocation. The resources and processes are represented by the graph's nodes, while their allocation relationships are shown by the graph's edges. A cycle in the graph of the RAG method denotes the presence of a deadlock. When a cycle is discovered, at least one resource needed by another process in the cycle is being held by each process in the cycle, causing a deadlock. The RAG method is a crucial tool in contemporary operating systems due to its high efficiency and ability to spot deadlocks quickly.
.png)
Conclusion
In conclusion, recovering from a deadlock in an operating system involves detecting the deadlock and then resolving it by either terminating some of the involved processes or preempting resources. These actions help free up the system and restore normal operations, though they may cause temporary disruptions.
Similar Reads
Operating System Tutorial An Operating System(OS) is a software that manages and handles hardware and software resources of a computing device. Responsible for managing and controlling all the activities and sharing of computer resources among different running applications.A low-level Software that includes all the basic fu
4 min read
OS Basics
Process & Threads
CPU Scheduling
Deadlock
Memory & Disk Management
Memory Management in Operating SystemMemory is a hardware component that stores data, instructions and information temporarily or permanently for processing. It consists of an array of bytes or words, each with a unique address. Memory holds both input data and program instructions needed for the CPU to execute tasks.Memory works close
7 min read
Fixed (or static) Partitioning in Operating SystemFixed partitioning, also known as static partitioning, is one of the earliest memory management techniques used in operating systems. In this method, the main memory is divided into a fixed number of partitions at system startup, and each partition is allocated to a process. These partitions remain
8 min read
Variable (or Dynamic) Partitioning in Operating SystemIn operating systems, Memory Management is the function responsible for allocating and managing a computerâs main memory. The memory Management function keeps track of the status of each memory location, either allocated or free to ensure effective and efficient use of Primary Memory. Below are Memo
4 min read
Paging in Operating SystemPaging is the process of moving parts of a program, called pages, from secondary storage (like a hard drive) into the main memory (RAM). The main idea behind paging is to break a program into smaller fixed-size blocks called pages.To keep track of where each page is stored in memory, the operating s
8 min read
Segmentation in Operating SystemA process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the exact sizes are called segments. Segmentation gives the user's view of the process which paging does not provide. Here the user's view is mapped to physical memory. Types of Segmentatio
4 min read
Segmentation in Operating SystemA process is divided into Segments. The chunks that a program is divided into which are not necessarily all of the exact sizes are called segments. Segmentation gives the user's view of the process which paging does not provide. Here the user's view is mapped to physical memory. Types of Segmentatio
4 min read
Page Replacement Algorithms in Operating SystemsIn an operating system that uses paging for memory management, a page replacement algorithm is needed to decide which page needs to be replaced when a new page comes in. Page replacement becomes necessary when a page fault occurs and no free page frames are in memory. in this article, we will discus
7 min read
File Systems in Operating SystemA computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data.File systems are a crucial part of any operating system
8 min read
File Systems in Operating SystemA computer file is defined as a medium used for saving and managing data in the computer system. The data stored in the computer system is completely in digital format, although there can be various types of files that help us to store the data.File systems are a crucial part of any operating system
8 min read
Advanced OS
Practice