Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

WEEK 8 – Operating System

CONCEPT:

Deadlock is a condition in which a process P1 wants a resource that is held by any other process
P2 & process.
P2 wants a resource that is held by process P1.
No processes that are in deadlock can further proceed and get blocked.
EXPLANATION:
Deadlock detection algorithm is used to detect any chance of deadlock while allocating
resources to the
processes.
If any process will cause or has a chance of creating a deadlock, then this algorithm will not give
resources to that.
process causing deadlock.

Steps of deadlock detection algorithm:


1.Deadlock detection algorithm will check that process requesting resources are
available.
Request <= Available
2. If the above condition gets satisfied then the algorithm will allocate the resources demanded
by the process.
Also, after fulfilling the request, availability gets added with the allocation of that process.
available = available + allocation
3. Else, the algorithm will keep the process till its next turn.
CALCULATION:

Step 1.

Process P0 requests instances (0,0,0) and it is available.


(0,0,0) <= (0,0,0)
so, P0 will get the resources:
available = (0,0,0) + (0,1,0) = (0,1,0) {A - 0 instance, B - 1 instance, C - 0 instance}
Step 2.
Process P1 is requesting instances (2,0,2) it is not available.

(2,0,2) > (0,1,0) {request < available}

So, P2 will wait.


Step 3.
Process P2 is requesting instances (0,0,0) and it is available.

(0,0,0) < (0,1,0)


so, P2 will get the resources:
available = (0,1,0) + (3,0,3) = (3,1,3) {A - 3 instance, B - 1 instance, C - 3 instance}
Step 4.
Process P3 is requesting instances (1,0,0) and it is available.

(1,0,0) < (3,1,3)


so, P3 will get the resources:
available = (3,1,3) + (2,1,1) = (5,2,4) {A - 5 instance, B - 2 instance, C - 4 instance}
Step 5.
Process P4 is requesting instances (0,0,2) and it is available.

(0,0,2) < (5,2,4)


so, P4 will get the resources:
available = (5,2,4) + (0,0,2) = (5,2,6) {A - 5 instance, B - 2 instance, C - 6 instance}
Step 6.
Process P1 requests instances (2,0,2) and it is available.

(2,0,2) < (5,2,6)


so, P1 will get the resources:
available = (5,2,6) + (2,0,0) = (7,2,6) {A - 7 instance, B - 2 instance, C - 6 instance}
Also, detection algorithms create safe sequences i.e. sequence of resource allocated processes
without any deadlock.

Here, safe sequence is <P0, P2, P3, P4, P1>


Hence, the system is not in a deadlock state.

You might also like