For working professionals
For fresh graduates
More
What do you think happens when there are multiple processes running on a single system simultaneously?
Each process will have to compete for resource allocation so that it can be completed first. The processes, thus, get stuck and do not make any progress. This condition is termed as a “Deadlock in Operating System.”
Having worked in the line of software engineering, I have had my fair share of experience with deadlocks numerous times. This is what I will discuss with you in this tutorial.
Let me teach you all you need to know about a deadlock in OS including the types of deadlock in OS, how to remove them, and their advantages and disadvantages.
Happy reading!
We all understand that every process taking place in a system requires the assistance of a resource in order to attain execution. This resource can either be the central processing unit (CPU) of the system or some other plugged-in device. When one process ends, the resource that was in use is released.
To properly explain the concept of Deadlock, here’s an example. Refer to the picture below. Here, P1 and P2 are two processes and R1 and R2 are two resources.
P1 is actually assigned to R1, whereas it waits for R2. On the other hand, P2 is assigned to R2, but it ends up waiting for R1.
As a result, neither of the processes are getting executed, because the resources that are needed by them are not being vacated. This is a classic example of deadlock in OS.
If your concept of the two terms “deadlock” and “starvation” is not clear, here is an explanation for the same. Let me first put it in simple terms.
In case of deadlock, the execution of processes takes longer because resource allocation takes time. On the other hand, in case of starvation, resource is never allocated to low-priority processes, as a result of which they are never executed,
I will list down the differences between the two in the table below:
Parameter | Deadlock | Starvation |
What is it? | Here, there is more than one process running in a system. This hinders the execution of the processes due to no resource allocation. | Resources are never allocated to low-priority processes. As a result, they are never executed. |
Also known as | Circular wait | Lived lock |
Resource allocation | Resource allocation is not done. | Resources are allocated to high-priority processes. |
Execution | No processes are executed. | Only high-priority processes are executed. |
It is not always necessary that whenever there is more than one process running in a system requiring the involvement of multiple resources, the system will face a deadlock.
There are four conditions that lead to a deadlock in OS. I have listed them down below:
This causes them to be also known as "circular wait."
Hope this gives you a clear idea about the four conditions for deadlock in OS. Learn more about operating systems here.
Are you trying to figure out methods for handling deadlock in OS? Let me jot down the ways:
In this method, you need to identify a deadlock situation and look for ways in which it can be recovered. Users can abort the processes that can result in potential deadlocks.
It is advisable to go by this process one step at a time. This will help to detect which process is causing the deadlock. Another way of preventing it could be to free the resources from allocation until the deadlock condition perishes. This is known as "resource preemption."
If a user is able to avoid any of the four conditions that are responsible for causing a deadlock, it might be possible to prevent one.
When a process seeks resource allocation, an algorithm is run to determine whether a resource is safe to be allocated.
If it is found unsafe, the request for allocation is turned down. This algorithm is known as the deadlock avoidance in OS technique.
You can look into a resource allocation graph in operating system, which is a pictorial representation that provides information on the processes that are using some resources or are awaiting the allocation of some resources.
This resource allocation graph in OS example that I have highlighted provides information on whether there are resources available to be used by other processes.
Some operating systems like Windows and UNIX are obvious to deadlocks. They, therefore, ignore the situation of deadlock whenever it arises.
This technique is called the "Ostrich algorithm." In case a situation of deadlock arises, you simply have to reboot the PC, and you will be able to resolve the deadlock issue in no time.
There are several factors you can take advantage of when you encounter a deadlock in OS. They are:
Now that I have discussed the advantages of deadlock in operating system, let me throw light on the other side of the coin as well. The disadvantages of deadlock in OS are as follows:
Such frequent recovery and deduction processes may impact the overall performance of the system, and induce latency. This can have a negative impact on time-sensitive applications where responsiveness may be crucial.
I hope I've clarified what a deadlock in OS is. With this basic understanding, spotting and resolving deadlocks becomes simpler. Knowing how to prevent deadlocks is crucial for keeping systems stable and efficient.
If you're keen on delving deeper into such intuitive concepts, consider exploring upGrad. The platform offers tailored courses designed by experts, ideal for working professionals seeking to enhance their skills.
During a deadlock in OS, processes are blocked because one resource is being used by a process. The processes in queue have to wait for another resource to be allocated. The four types of deadlocks are- mutual exclusion, hold and wait, no preemption, and circular wait.
We can understand deadlock as two trains running in opposite directions towards each other on a single track. Both the trains wait for the track to be cleared so that they can move forward, but neither of them can actually proceed.
Deadlock is a condition in which two or more processes access the same resource, and both fail to access it simultaneously, thereby causing the process to get stuck. It can be prevented by detecting and preventing, avoidance, and ignorance.
The four components include mutual exclusion, no preemption, hold and wait, and circular wait.
Deadlock in OS happens when there are more than one process awaiting to utilize a single resource, whereas neither is able to do so.
The most common solution for a deadlock in OS is to cancel, restart,or abort a process.
Algorithms can help detect deadlocks in operating systems.
You can free up resources by using the recovery method when you encounter a deadlock.
Deadlocks are important in operating systems because they help make a system stable and efficient.
Yes. Deadlocks can be easily removed.
Pavan Vadapalli
Director of Engineering @ upGrad. Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working …Read More
Talk to our experts. We are available 7 days a week, 9 AM to 12 AM (midnight)
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
1.The above statistics depend on various factors and individual results may vary. Past performance is no guarantee of future results.
2.The student assumes full responsibility for all expenses associated with visas, travel, & related costs. upGrad does not provide any a.