Deadlock Errror Detection, Deadlock Prevention and Deadlock avoidance Algorithm in Operating System

There're four way to detect Deadlock condition in operating system, 1.Hold and wait 2. Mutual exclusion 3.No preemption 4.Circular wait. Read careful

Abstract

How the Deadlock situation arise during the process execution and how to prevent concurrently  execution  of a process.

When Deadlock Condition occurs? 

As we know operating system are able to handle many job or process simultaneously, this process are managed by the control unit which focus on every request process get the exact resources without any inflection. It may be possible that one process get request many resources to performing operations, the requested process are stored in a queue where mention  all the resource that are required during the job execution or process  execution. 

Sometimes it may also be possible a  process request  any type of resource that are already taken by the other process that time requested processes need to wait for that resources while it get free by the another process. Sometime in minor cases having a chance that process never get requested resource and the working cycle got effected and will never finished. This types of situation take the operating system in Deadlock position. Now let's discuss how to handel Deadlock Detection  and Deadlock prevention techniques and algorithm.


Four Definition of (Deadlock Detection) ,which describes the Deadlock condition in operating system:

1. Mutual exclusion :

By a simple statement, a mutual exclusion is a  type of condition where one proces takes the resource as an unshareable property. And the second process  waits for it to be free but it never get free. This situation are responsible for inserting the operating system in Deadlock position. 

Example 1: 

Suppose that one process taking a resource for printing a photocopy of Nth numbers, in the meantime the next processe can never request to that resource until it released by Previous process by itself.  That time printer is not available for other processes thus the Deadlock condition is invoked. 

Example 2: 

In a file system, reading a file is a best example of shareable resources where many processes make a request  to reading the file in memory simultaneously without moving Deadlock position while File writing process is take place at only once  in a particular time. It is a appropriate  example of non-shareable resource that might be produced Deadlock condition when writing request comes more than one.

2. Hold and wait:

 Hold & wait is a situation where process request a resource but still waiting for another resource for completing  the task. This types of condition is also count as an Deadlock condition. In this phase the process is depend on a second resource which might be taken by someone else process. This type of situation is also responsible for Deadlock. A process cycle given below clear the whole concept.


3. No prempton:

It is a another type of Deadlock condition that occurs when certain resources occupy by a some process and has not been available to next one. It can be avoided by ensuring that requested resource has been  released by the occupied process, if they are, so allocate the resources to the requested process, and if not, so release that resources before allocate the requested resource to the process. No other process can use  any resource forcefully which is requested  by a previous process. Basically Request resource is stored in the queue where initialise all the necessary resource that will used during the execution. 

Example 3:

 The best example to avoid this Deadlock condition by, If a process occupies a resource for scanning the pages that time it does not request to another resource, it must de-allocate the requested resource then the next resource will get by the needed process.

4. Circular wait: 

As its name, it make a circle of resource and process, if circulation is made between process and resource then Circulation wait Deadlock condition inv

Circular  wait is a very common Deadlock condition that arises sometimes when some requested resource already occupied by different process, basically it is dependent to each other very closely. 

For Example, 

.


.

Process (A) waiting for Resource (X)

Resource (X) occupied by Process (B)

Process (B) is waiting for Resource (Y)

And Resource (Y) is occupied by  process (A)


P(A) --> R(X) --> P(B) --> R(Y) --> P(A)

    Circular wait condition 




☆》 DEADLOCK AVOIDANCE ALGORITHM: 

Deadlock Avoidance : During the Deadlock avoidance Algorithm we have to remember that the system do not fall under the circular wait condition during the entire execution of program/process. Let's quickly take an overview of Safe state and Unsafe state: 

Safe state:  Deadlock will not come ever if the system is under in safe state. No cycle will created in any circumstances, every process will released each resource after all the requirements fulfilled successfully. 

Unsafe state:  there is a possibility the Deadlock condition occur during the process execution if the system falls in unsafe state, there would be generated a Deadlock cycle.


》 Banker's Algorithm For Deadlock Avoidance

Banker's useful Key terms: 


Available :  the number of available resource are still remaining there.

Allocation : how many resources are allocated to the each process. 

Need: how many numbers of resources are still required to a process .

Max: the total number of resources required by a process. 







.

.

About the author

D Shwari
I'm a professor at National University's Department of Computer Science. My main streams are data science and data analysis. Project management for many computer science-related sectors. Next working project on Al with deep Learning.....

Post a Comment