Deadlock Recovery for Resource and Process

Aayushvats
4 min readApr 30, 2021
Deadlock

A Deadlock can describe as the traffic in a particular area i.e when there is a traffic jam in a particular area then 4 to 5 people has to go on one road but the opposite road people don’t allow to come , in a technical form more than one process request for one resource only then a situation comes as a deadlock.

In the above diagram, resource 1 is assigned to process 1 and process 1 is waiting for resource 2 and resource 2 is assigned to process 2 and process 2 is waiting for resource 1.

Deadlock can cause because of following conditions:-

  1. Mutual Exclusion:- Resources allocate only at one process at a time, means more than one process can’t control the same resource at a time.
Mutual Exclusion

In above diagram resource is held by only one process i.e process 1

2. Hold and Wait:- In this situation resource 2 and resource 3 is allocated to process 2 then also process 2 wants resource 1 for execution which is holding by process 1.

Hold and Wait

In the above diagram, resource 2 and resource 3 are holding process 2 and is requesting resource 1 which are held by process 1.

3. No Preemption:- Once a process hold a resource it can’t be taken away by another process.

No Preemption

In the above diagram, process 2 can’t take the resource 1 from the process 1.

4. Circular Wait:- One process is waiting for resource 1 which is held by another process which is waiting for the resource held by the third process and so on it will rotate in circular manner.

Circular Wait

In the above diagram, process 1 is waiting for resource 1 which is held by process 2 which is waiting for resource 2 which is held by process 1.

Handling Recovery:-

  1. Deadlock Prevention and Avoidance:- Make sure that the system does not allow the deadlock situation.
  2. Deadlock Detection and Recovery:- O.S doesn’t apply any mechanism for deadlock prevention therefore the system will consider that the deadlock will definitely occur. For that the o.s checks the system for any deadlock situation if any case situation is found o.s will recover the system using some recovery options.
  3. Deadlock Ignorance:- In this if any deadlock situation is occur the o.s will behave like the deadlock situation never occur.

Recovery of Deadlock:-

Deadlock Recovery For Resource and Process
  1. For Resource
  • Preempt the resource:- We can take one of the resource from the head of the process and give it to another process so that he will execute the process and give the resource back sooner.
  • Rollback to safe state:- System goes through different states to goes into deadlock situation or state. In this situation or state the o.s can rollback one step back to the safe state.To come back in safe state the o.s will check every state passing through it.If any deadlocks comes, so the o.s can go back one step back to the safe state.

2. For Process

  • Kill a Process:- In this recovery mode we can kill one process to come out from the deadlock situation but the main thing is to decide which process has to be killed.The o.s will kill that process which has done least amount of work until the deadlock situation come.
  • Kill all Process:- In this recovery mode we can kill all process but this will not much comfortable because all the process has to be execute from starting.

--

--