Nothing Special   »   [go: up one dir, main page]

Unit 4 Deadlock Bankers Algorithms Numerical

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

Example 1: Consider the system with 5 processes P0, P1, P2, P3, P4 and 3 resources types A, B, C (10, 5,

7). The following snapshot of the system has been given.

Allocation Max Available


A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 2 9 0 2
P3 2 1 1 2 2 2
P4 0 0 2 4 3 3
a) Find the need matrix.
b) Is the system in a safe state? If yes find the safe sequence.

Solution:

1) Need Matrix (max-allocation)

Need Matrix (max-allocation)


A B C
P0 7 4 3
P1 1 2 2
P2 6 0 0
P3 0 1 1
P4 4 3 1
2) Safety check using safety algorithm
a) For P0,
(7,4,3) > (3,3,2)
Need > available, so do not execute P0.
b) For P1,
(1,2,2) <= (3,3,2)
Need <= available, so execute P1.
Available=available + allocation
=(3,3,2) + (2,0,0) = (5,3,2)
c) For P2,
(6,0,0) > (5,3,2)
Need > available, so do not execute P2.
d) For P3,
(0,1,1) <= (5,3,2)
Need <= available, so execute P3.
Available= available + allocation
= (5,3,2) + (2,1,1) = (7,4,3)
e) For P4,
(4,3,1) <= (7,4,3)
Need <= available, so execute P4.
Available = (7,4,3) + (0,0,2) = (7,4,5)
f) For P0,
(7,4,3) <= (7,4,5)
Need <= available, so execute P0.
Available= (7,4,5) + (0,1,0) = (7,5,5)
g) For P2,
(6,0,0) <= (7,5,5)
Need <= available, so execute P2.
Available= (7,5,5) + (3,0,2) = (10,5,7)

Since, all the processes are executed, the system is in safe state and the safe sequence is: P1, P3, P4, P0,
P2

Example 2: Assume that there are three resources A, B, and C. There are 4 processes P0 to P3. At T0, we
have the following snapshot of the system.

Allocation Max Available


A B C A B C A B C
P0 1 0 1 3 1 1 2 1 1
P1 2 1 2 5 4 4
P2 3 0 0 3 1 1
P3 1 0 1 1 1 1
a) Find the need matrix.
b) Is the system in a safe state? If yes find the safe sequence.

Solution:

1) Need Matrix (max-allocation)

Need Matrix (max-allocation)


A B C
P0 2 1 0
P1 3 3 2
P2 0 1 1
P3 0 1 0

2) Safety check using safety algorithm


a) For P0
(2,1,0) <= (2,1,1)
Here, need <=available, so execute P0
Available = available + allocation
= (2,1,1) + (1,0,1)
= (3,1,2)
b) For P1
(3,3,2) > (3,1,2)
Here, need > available, so do not execute P1
c) For P2
(0,1,1) <= (3,1,2)
Here, need <= available, so execute P2
Available = available + allocation
= (3,1,2) + (3,0,0)
= (6,1,2)
d) For P3
(0,1,0) <= (6,1,2)
Here, need <= available, so execute P3
Available = available + allocation
= (6,1,2) + (1,0,1)
= (7,1,3)
e) For P1
(3,3,2) > (7,1,3)
Here, need > available, so do not execute P1

Here, the need of process P1 (3,3,2) is greater than the available resources (7,1,3) for resource B. So, we
cannot continue. Hence, the system is not in the safe state.

You might also like