0
2.0kviews
Consider the following snapshot of a system.

Subject: Operating System

Topic: Synchronization and Deadlocks

Difficulty: Medium

Process Max Allocation Available
A,B,C A,B,C A,B,C
P0 0,0,1 0,0,1 1,5,2
P1 1,7,5 1,0,0
P2 2,3,5 1,3,5

Using Banker's algorithm answer the following questions

i) How many resources are there of type (A, B,C)?

ii) What are the contents of the Need matrix?

iii) Is the system in a safe state? Why?

1 Answer
0
43views

[i] How many resources are there of type (A, B, C)?

The Total Amount of Resources = Sum of Columns of Allocation + Available Resource

= [2 3 6] + [1 5 2] = [3 8 8]

[ii] What are the contents of the Need matrix?

Calculation of the Need Matrix

Need [i] = Max [i] - Allocation [I]

Need for P0: (0, 0, 1) – (0, 0 , 1) = (0, 0, 1)

Need for P1: (1, 7, 5) – (1, 0, 0) = (0, 7, 5)

Need for P2: (2, 3, 5) – (1, 3, 5) = (1, 0, 0)

Need Matrix looks like in the following manner:

b2

[iii] Is the system in a safe state? Why?

Available Resources are Available = (1, 5, 2)

Now check if each type of resource request is available for each process or not

Step 1: For Process P0:

Need <= Available

0, 0, 1 <= 1, 5, 2 condition is True.

New available = available + Allocation

(1, 5, 2) + (0, 0, 1) => 1, 5, 3

Step 2: For Process P1:

Need <= Available

0, 7, 5 <= 1, 5, 3 condition is False.

Step 3: For Process P2:

Need <= Available

1, 0, 0 <= 1, 5, 3 condition is True.

New available = available + Allocation

(1, 5, 3) + (1, 3, 5) => 2, 8, 8

Step 4: Now again check for Process P1:

Need <= Available

0, 7, 5 <= 2, 8, 8 condition is True.

New available = available + Allocation

(2, 8, 8) + (1, 0, 0) => 3, 8, 8

Hence, execute the banker's algorithm to find the safe state and the safe sequence like P0, P2, and P1 for available resources (1, 5, 2)

Order of Safe Sequence = P0, P2, P1

The system allocates all the needed resources to each process. So, we can say that the system is in a safe state.

Please log in to add an answer.