Define Deadlock. Explain deadlock detection , prevention, recovery.


Deadlock 

A deadlock happens in operating system when two or more processes need some resource to complete their execution that is held by the other process.

Deadlock in Operating System

In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in deadlock as each of them needs the other’s resource to complete their execution but neither of them is willing to relinquish their resources.

Deadlock Detection

  1. If resources have single instance:
    In this case for Deadlock detection we can run an algorithm to check for cycle in the Resource Allocation Graph. Presence of cycle in the graph is the sufficient condition for deadlock.

  2. If there are multiple instances of resources:
    Detection of the cycle is necessary but not sufficient condition for deadlock detection, in this case, the system may or may not be in deadlock varies according to different situations.

Deadlock prevention

It is very important to prevent a deadlock before it can occur. So, the system checks each transaction before it is executed to make sure it does not lead to deadlock. 
If there is even a slight chance that a transaction may lead to deadlock in the future, it is never allowed to execute.

Deadlock Recovery
A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is time and space consuming process. Real-time operating systems use Deadlock recovery.

Recovery method

  1. Killing the process: killing all the process involved in the deadlock. Killing process one by one. After killing each process check for deadlock again keep repeating the process till system recover from deadlock.
  2. Resource Preemption: Resources are preempted from the processes involved in the deadlock, preempted resources are allocated to other processes so that there is a possibility of recovering the system from deadlock. In this case, the system goes into starvation.

Comments

Popular posts from this blog

What is the process and project matrics? Explain 3 P's in software engineering.

Explain general format of Software Requirement Specification (SRS).

Difference between IPv4 and IPv6.