If a system does not use a deadlock prevention technique or the deadlock avoidance technique, there is a probability that a deadlock will occur. In order to avoid deadlocks, the operating system examines the system for any deadlocks on a regular basis. The OS will recover from the deadlock using recovery mechanisms after it has been discovered.
In this article, we will look more into the Deadlock Detection and Recovery in Operating Systems according to the GATE Syllabus for (Computer Science Engineering) CSE. Let us read ahead to find out more about it.
Table of Contents
How to Detect Deadlock in Operating Systems?
The OS does not use any mechanisms to avoid or prevent deadlocks in this approach. As a result, the system predicts that the deadlock will occur. The OS periodically scans the system for any deadlocks in order to avoid them. If any deadlocks are discovered, the OS will attempt to restore the system using several ways.
The OS’s primary responsibility is to detect deadlocks. With the help of the resource allocation graph, the OS can detect deadlocks.
If a cycle forms in a system with single instanced resource types, there will undoubtedly be a deadlock. Detecting a cycle, on the other hand, is insufficient in a graph of the multiple instanced resource type. By turning the resource allocation graph into the allocation matrix as well as the request matrix, we must apply the safety algorithm to the system.
Deadlock Recovery in Operating System
OS examines either resources or processes to recover the system from deadlocks.
For Resource
Preempt the resource
We can take one of the resources from the resource owner (process) and give it to another process in the hopes that it will finish the execution and release the resource sooner. Choosing a resource that will be snatched will be challenging.
Rollback to a safe state
To reach the deadlock state, the system happens to go through several states. The operating system has the ability to restore the system to a previous safe state. The OS must implement checkpointing at each state for this to work.
When we reach a deadlock, we must reverse all allocations and return to the prior safe state.
For Process
Kill a process
Our problem can be solved by killing a process; however, the bigger issue is deciding which process to kill. A process that has done the least amount of work till now is usually killed by the operating system.
Kill all processes
This is not a persuasive strategy, but it may be used if the problem becomes extremely serious. Killing all processes will result in system inefficiencies because all processes will have to start over.
Keep learning and stay tuned to get the latest updates on GATE Exam along with GATE Eligibility Criteria, GATE 2023, GATE Admit Card, GATE Syllabus, GATE Previous Year Question Paper, and more.
Also Explore,
- Batch Operating System
- Binary Semaphores in Operating System
- Contiguous Memory Allocation in Operating System
- Counting Semaphores in Operating System
- Deadlock Prevention in Operating System
- Distributed Operating System
- Dynamic Partitioning in Operating System
- Fixed Partitioning in Operating System
- Functions of Operating System
- Operating System GATE Questions
- Methods for Handling Deadlock in Operating System
- Multiprocessing Operating System
- Multiprogramming Operating System
- Multitasking Operating System
- Network Operating System
- Non-Contiguous Memory Allocation in Operating System
- Operating System Services
- Paging in OS
- Process in Operating System
- Process Scheduler in Operating System
- Process Scheduling in Operating System
- Process State in Operating System
- Real-Time Operating System
- Resource Allocation Graph in Operating System
- Semaphores in Operating System
- Time-Sharing Operating System
- Types of Operating System
Comments