TEchMyEducation

easy tech learning...

What is Deadlock? conditions of deadlock, deadlock prevention, deadlock avoidance,deadlock detection, disadvantages of deadlock

No comments

What is Deadlock? conditions of deadlock, deadlock prevention, deadlock avoidance,deadlock detection, disadvantages of deadlock

Hello friends! Today we will read about Deadlock in (what is the deadlock in the operating system?) In this post and will also see its conditions. Read it completely. So let's start: -

Deadlock
Deadlock is a condition in which two or more processes fight or require for only one resource, due to which no one is able to access the resource.

In other words, " Deadlock condition occurs when two or more resources is requiring a resource to complete their process execution but that require resources is in use by another process by which the execution of process wont be completed ".

It is a situation in the operating system in which one process  goes to waiting state because the resource is held by another process.

For example suppose there are two friends who wants to ride bike due to which both are fighting.One has a bike key and the other has money for petrol.
So in this condition neither of the two friends are able to ride bike and neither of them is ready for cooperation.This is called deadlock.

Fig: -deadlock

In picture we have two processes x1 and x2 and two resources Rk1 and k2.k1 is allocated to process x1, and k2 is allocated to process x2. But x1 needs k2 to complete the process so it requests k2, but k2 is already allocated with x2.

Same as process x2 requires k1 to complete its execution, but k1 is already allocated with x1.
Both x1 and x2 will always wait for each other's resources. This is called DEADLOCK.

Conditions of Deadlock

Deadlock has four conditions, which are as follows: 

  • mutual exclusion
  • hold & wait
  • no preemption
  • circular wait
1: - Mutual exclusion - In this case, there is one such resource which cannot be shared between processes.

In this, only one process can use the resource at a time. That is, no two processes can use one resource at a time.

2: - Hold & wait - In this, the process keeps holding one resource while waiting for another resource.

3: - No preemption - A resource which is allocated for a process cannot be forcibly allocated to another process. Process releases the resource on its own.

4: - Circular wait - In this, every process waits for a resource which is held by another process and all the processes wait for resources in the form of a circle. Therefore it is called circular wait.

Deadlock Prevention - Stop deadlock

To prevent deadlock, we have to prevent any one of the four conditions above the deadlock from happening. Only then can we stop the deadlock from happening.

Mutual exclusion - If we can share a resource, then we can prevent mutual exclusion from happening. But we have many resources which cannot be shared such as - tape driver, printer etc. Because of this we cannot always prevent deadlock by mutual exclusion.

Hold & Wait - If we allocate the resource before the execution of the process, we can prevent the condition of hold and wait from happening. But its disadvantage is that it reduces the utilization of the device very much.

No preemption - We can prevent this condition from happening by releasing a resource held by a process.

Circular wait - To prevent this condition, we can allocate resources in decreasing or increasing order of the process.

Deadlock avoidance -

Deadlock prevention algorithm is much less effective as it reduces the utilization of the device and the throughput of the system. But we can avoid deadlock.

To avoid the deadlock, we use the bank penalty algorithm.

Deadlock Detection

The os can detect deadlocks using a resource scheduler. Resource scheduler helps to track the resources allocated to all the processes of the operating system. So whenever a deadlock occurs, it is solved using algorithms.

Disadvantage of Deadlock

Its disadvantages are as follows: -

This causes delays in the execution of the process.
In this, the process should know what resource it will need in the future.
Preemption occurs more often than necessary.
Benefits of Deadlock -
Its benefits are as follows: -

This situation is good for processes that perform only one task.
deadlock avoidance requires no preemption.
references: -

https://www.javatpoint.com/os-deadlocks-introduction
https://www.geeksforgeeks.org/introduction-of-deadlock-in-operating-system/

Request: - If you liked this post, then share it with your friends and if you know anything more about deadlock.Tell us through the comments.

I keep bringing you fresh new notes and articles. If you have any suggestion or have any question related to any subject, then you can also tell it by commenting below. I will put it in 1-2 days. Thanks.

No comments :

Post a Comment