Consider the following snapshot of the system:

Process / Allocation
A B C / Max
A B C / Available
P0 / 0 1 0 / 7 5 3 / 3 3 2
P1 / 2 0 0 / 3 2 2
P2 / 3 0 2 / 9 02
P3 / 2 1 1 / 2 2 2
P4 / 0 0 2 / 4 3 3

a)  Determine the system in a save state.

b)  Can the request from P1 of resource (1,0,2) be made? Explain.

Solution:

a)  In order to find the system in a save state we have to apply the safety algorithm:

The system with need matrix:

Process / Allocation
A B C / Max
A B C / Need / Available
A B C
P0 / 0 1 0 / 7 5 3 / 7 4 3 / 3 3 2
P1 / 2 0 0 / 3 2 2 / 1 2 2
P2 / 3 0 2 / 9 0 2 / 6 0 2
P3 / 2 1 1 / 2 2 2 / 0 1 1
P4 / 0 0 2 / 4 3 3 / 4 3 1

Let Work and Finish and SAVE be vectors of length m, n and n respectively.

Initialize:

Work = Available=[3 3 2]

Finish [] = [F F F F F]

SAVE[]=[0, 0, 0, 0, 0]

Now we have to find the process Pi for which Finish[i] =F and Needi < Work

For P1, it is found, it can be added to safe sequence. So

Work = work+Allocationi =[3 3 2]+[2 0 0] = [5 3 2]

Finish [] = [F T F F F]

SAVE[]=[P1, 0, 0, 0, 0]

For P3, it is found, it can be added to safe sequence. So

Work = work+Allocationi =[5 3 2]+[ 2 1 1] = [7 4 3]

Finish [] = [F T F T F]

SAVE[]=[P1, P3, 0, 0, 0]

For P4, it is found, it can be added to safe sequence. So

Work = work+Allocationi =[7 4 3]+[ 0 0 2] = [7 4 5]

Finish [] = [F T F T T]

SAVE[]=[P1, P3, P4, 0, 0]

For P0, it is found, it can be added to safe sequence. So

Work = work+Allocationi =[7 4 5]+[ 0 1 0] = [7 5 5]

Finish [] = [T T F T T]

SAVE[]=[P1, P3, P4, P0, 0]

For P2, it is found, it can be added to safe sequence. So

Work = work+Allocationi =[7 5 5]+[ 3 0 2] = [10 5 7]

Finish [] = [T T T T T]

SAVE[]=[P1, P3, P4, P0, P2]

Since we have found the save sequence as [P1, P3, P4, P0, P2]. So, The system is in a save state.

b)  For the request from P1 (1,0,2). First we have to apply the resource request algorithm. Secondly we have to find a save sequence using safely algorithm.

Check for Requesti £ Needi

(1 0 2) £ 1 2 2 --- Satisfied.

Check for If Requesti £ Available,

(1 0 2) £ 3 3 2 --- Satisfied.

Now update our system to a intermediate step:

Available = Available – Request;= [3 3 2]-[1 0 2]=[2 3 0]

Allocationi = Allocationi + Requesti = [2 0 0]+ [1 0 2]=[3 0 2]

Needi = Needi – Requesti =[1 2 2]- [1 0 2]=[0 2 0]

Therefore the intermediate snapshot of the system is:

Process / Allocation
A B C / Max
A B C / Need / Available
A B C
P0 / 0 1 0 / 7 5 3 / 7 4 3 / 2 3 0
P1 / 3 0 2 / 3 2 2 / 0 2 0
P2 / 3 0 2 / 9 0 2 / 6 0 2
P3 / 2 1 1 / 2 2 2 / 0 1 1
P4 / 0 0 2 / 4 3 3 / 4 3 1

Now again you have to apply safety algorithm for finding the safe sequence described in part (a)

---

---

if you found the save sequence then

·  The request can be granted.

·  Intermediate system will be committed to final system

Otherwise

·  The request can not be granted.

·  Intermediate system will be roll backed to previous system

It can not be guaranteed that the solution is correct