Ticker

6/recent/ticker-posts

Header Ads Widget

Introduction of Deadlock in Operating System

In this article I am gone a show you what is deadlock in operating system and also Necessary Conditions for deadlock  I will explain you so let’s get start.

 

Deadlock in Operating System

What is Deadlock?

Here the first question arise that what is the mean of deadlock so let’s understand If two or more processes are waiting for some event but that event does not happen it calls deadlock. Here we can say this two processes are at deadlock situation.

 

Real life example of Deadlock

Let’s understand with a simple real life example suppose I went to the bank and I want to open a bank account so I ask to that employee that I want to open a bank account but that person is saying you need to deposit some minimum amount first but I want to open account first and then I want to deposit money.

In this case I am waiting for an event to open an account and that person is waiting for money deposit so both are waiting for some event which never gone a happen so we can say it is deadlock situation.

 

Example of Deadlock with diagram

Here I present you one diagram in this diagram there is two process and two resources so let’s see.

Deadlock in Operating System

In this diagram resource1 allocated to process1 but process1 require resource2 but resource2 allocated to process2 but process2 requires resource1 so it comes deadlock situation.

 

Necessary Conditions for deadlock 

There are four necessary conditions for deadlock and that four are:

·         Mutual Exclusion

·         No Preemption

·         Hold and Wait

·         Circular Wait

Let’s understand all four one by one

 

Mutual exclusion

Mutual exclusion means whatever the resource you are using all the resources must be used by all the processes in a mutual exclusive manner which means one by one interleaving is not allowed.

Let’s take a simple example suppose there are two computer connected with one printer and both computer start the process to print something so printer print both at the same time it creates the mess this is not allowed.

 

No Preemption

It means suppose one process is holding one resource at that time another process comes to that resource so now process one is not allowed to leave that resource so no preemption allowed there.

Let’s take one simple real life example suppose if you have one girlfriend you have lot of money and then another man comes between you and your girlfriend’s life at that time you can’t leave your girlfriend I hope you understood.  

 

Hold and wait

In this suppose one process have one resource but it demands for one more resource which is already occupied by other process so in this situation you need to just hold that one resource and wait for resource that’s it.

 

Circular wait

Let’s understand threw diagram here I presenting you one diagram. In this diagram there is one process P1 holds Resource R1 and same as process P2 holds Resource R2 and same as process P3 holds Resource R3 and Process P2 wants Resource R1 same Process P3 wants Resource R2 same process P1 wants Resource R3 so it calls circular wait situation.

Deadlock in Operating System

So here if the situation has qualify for all conditions then only it becomes deadlock situation hope so you understand all this.

 

methods to handling deadlock situations

So there are mainly four methods for deadlock handling and here it is.

1.   Deadlock ignorance (Ostrich method)

2.   Deadlock prevention

3.   Deadlock avoidance

4.   Deadlock detection and recovery

 

Let’s understand all four one by one with small examples.

 

Deadlock ignorance

When the deadlock situation is occurs just ignore the situation most of the operating system using this strategy many times we face this situation in are laptops. when type of situation  occurs with us in laptop at that time the laptop gone a stop or hang at that time we just restart the pc and its start working back so it calls deadlock ignorance and we can also say ostrich method.

 

Why we ignore deadlock?

Most of the time operating system ignores the deadlock so here we think why they are ignore why they can’t find solution and implement in operating system so the answer is deadlock situation occur once or twice in a year for this very small situation if we wrote thousands of line code and implement into OS then it affects the speed of OS that’s why we are ignoring the deadlock.

 

Deadlock prevention

Here in this method we try to find solution of deadlock which means we find the solution and apply on that and are system start running again.

So here we think how to solve deadlock solution is hope so you remember that four necessary condition if any process wants to be deadlock situation it needs to be true all four conditions so the solution is we just make any one condition false so it can’t be deadlock situation so it calls deadlock prevention.

 

Deadlock avoidance

We can do Deadlock avoidance with the help of Banker’s Algorithm.

Banker’s Algorithm is used to come out of the situation when deadlock occurs it checks that are system is safe from deadlock or not?  If the system is safe then if finds the solution otherwise it can’t give access to resources of system. So it calls deadlock avoidance with the help of Banker’s Algorithm.

 

Deadlock Detection and recovery

Here deadlock detection means the system try to detect that it is deadlock or not there are so many algorithms in system which detects the deadlock and once it find that is deadlock then system try to recover the deadlock so it calls deadlock detection and recovery. So I hope you understand full topic.

 

After reading this full article on what is deadlock in operating system or Deadlock in OS if you have any query you can ask me in comment section and if you like the article do comments and do not forget to share this article with you friends and for daily updates do email subscription and thank you for reading this article.

 

Related Posts :

Post a comment

0 Comments