Tutorial Playlist
47 Lessons1. Introduction to Operating System
2. Types of Operating Systems
3. Linux Operating System
4. An Introduction To Unix Operating System
5. Ubuntu Operating System
6. MS DOS Operating System
7. Mobile Operating System
8. Understanding Functions of Operating System
9. Components of Operating System
10. Understanding the Kernel in Operating Systems
11. Structure of Operating System
12. Process in Operating System
13. What is Bios
14. What is Booting in Computer
15. What is Interrupt in Operating System?
16. Process Control Block in Operating Systems
17. Threads in Operating System
18. Process Synchronization in OS
19. Critical Section in OS
20. Semaphore in Operating System
21. Deadlock in Operating System
Now Reading
22. Deadlock Prevention in OS
23. Paging in Operating System
24. Segmentation in Operating System
25. Virtual Memory in Operating System
26. File System in Operating Systems
27. Page Table in OS
28. Round Robin Scheduling in Operating System
29. Shortest Job First Scheduling Algorithm
30. Priority Scheduling in OS
31. Page Replacement Algorithms in Operating System
32. Race Condition in OS
33. Distributed Operating System
34. Navigating Contiguous Memory Allocation in Operating Systems
35. Fragmentation in Operating System
36. Banker’s Algorithm in OS
37. Context Switching in OS
38. First Come First Serve (FCFS) Scheduling Algorithm in Operating System
39. Understanding Inter Process Communication in OS
40. Multiprogramming Operating System
41. Python OS Module
42. Preemptive Priority Scheduling Algorithm
43. Resource Allocation Graph in OS
44. Scheduling Algorithms in OS
45. System Calls In Operating System
46. Thrashing in Operating Systems: A Deep Dive
47. Time Sharing Operating System
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
Motivated to leverage technology to solve problems. Seasoned leader for startups and fast moving orgs. Working on solving problems of scale and l…Read More
Talk to our experts. We’re available 24/7.
Indian Nationals
1800 210 2020
Foreign Nationals
+918045604032
upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enrolling. upGrad does not make any representations regarding the recognition or equivalence of the credits or credentials awarded, unless otherwise expressly stated. Success depends on individual qualifications, experience, and efforts in seeking employment.
upGrad does not grant credit; credits are granted, accepted or transferred at the sole discretion of the relevant educational institution offering the diploma or degree. We advise you to enquire further regarding the suitability of this program for your academic, professional requirements and job prospects before enr...