Deadlock in Operating System: Things that You Must Know about It
Deadlock in operating system is one of the most important concepts you must know. It is the basic topic in the operating system that every computer software student should aware. No bother if you are preparing or not preparing for placement or want to be the master or not in the operating system, every computer science folks must know what is deadlock and how it occurs…
Here is what we must know about Deadlock in Operating System
Definition of Deadlock in Operating System
Deadlock is the condition that occurs when two processes wait for each other to complete and halts without proceeding further. Here two processes wait for the resources acquired by each other.
Deadlock mostly occurs in multitasking or client-server architecture where resource get shared among multiple processes. If one process wants to access the resources which are acquired by other processes, the process needs to wait until resource get released by other processes.
This deadlock problem should have to be resolved by Operating System as all the resource managements are carried out at operating system level. But this does not get resolve every time and system gets hanged.
Suppose there are multiple clients want to access database table (resource) at the server side. But the server can not give access to all the clients to modify data at the same time. If the server allows multiple clients to modify data in the database table in the same time, data violation will occur.
Now consider the Deadlock in Operating System scenario…
Client1 locks and holds the table1 from the database DB.
Client1 wait for table2 from the same database to proceed.
Client2 locks and holds the table2 from the database DB.
Client2 wait for table1 from the same database to proceed.
Client1 and Client2 are the two processes
Database table1 and table2 are the two resources.
Both clients can not proceed further as both are waiting for the resources hold by each other. So the Deadlock occurs.
Necessary Conditions to Occur Deadlock
There are multiple necessary conditions to occur deadlock in operating system. Even if one condition does not get satisfied, deadlock cannot occur. These conditions are as follows.
- Mutual Exclusion
- Hold and Wait
- No Preemption
- Circular Wait
If you want not to occur deadlock, you should have to care not to satisfy any one of the conditions mentioned above.
Deadlock handling Strategies
There are multiple deadlocks handling strategies not to occurs deadlock. We can prevent the deadlock not to occur and it is the optimal solution. But preventing system not to occur deadlock is not easy as we require prior information about processes as well as resources. On other hands, if it occurs we have recovery mechanism.
There are four types of strategies to handle the deadlock. These are as follows
- Deadlock Prevention
- Deadlock Avoidance
- Deadlock Detection and Recover
- Deadlock Ignorance
In this post, I have shared basic concept of deadlock in operating system. We will discuss necessary conditions to occur deadlock, how to prevent deadlock, Deadlock handling Strategies in detail in the upcoming articles. Kindly Subscribe your email id below, I will update you once I will post next article.