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

Bankers Algo-Atinen Lab

Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 10

Allocation Max Available

Processes A B C A B C A B C
P0 1 1 2 4 3 3 2 1 0
P1 2 1 2 3 2 2
P2 4 0 1 9 0 2
P3 0 2 0 7 5 3
P4 1 1 2 1 1 2

Requirements
1. calculate the content of the need matrix
2. check if the system is in a safe state
3. determine the total sum of each type of resource

Solution:
1. The content of the need matrix can be calculated by using the formula given below:
Need = Max - Allocation

Need
Processes A B C
P0 3 2 1
P1 1 1 0
P2 5 0 1
P3 7 3 3
P4 0 0 0

2. To check if the system is in a safe state, check the processes below:

Safe sequence:
1. For process PO
Need = (3, 2, 1)
Available = (2, 1, 0)
Need <= Available = False
Therefore, the system will move to the next process.

2. For process P1
Need = (1, 1, 0)
Available = (2, 1, 0)
Need <= Available = True
Therefore, request of P1 is granted, if granted Available value will be changed according to the formula below:
Available = Available + Allocation
Available = (2, 1, 0) + (2, 1, 2)
New Available = (4, 2, 2)

3. For process P2
Need = (5, 0, 1)
Available = (4, 2, 2)
Need <= Available = False
Therefore, the system will move to the next process.

4. For process P3
Need = (7, 3, 3)
Available = (4, 2, 2)
Need <= Available = False
Therefore, the system will move to the next process.

5. For process P4
Need = (0, 0, 0)
Available = (4, 2, 2)
Need <= Available = True
Therefore, the request of P4 is granted. Then change the Available according to the formula below:
Available = Available + Allocation
Available = (4, 2, 2) + (1, 1, 2)
New Available = (5, 3, 4)

6. Now, check again the process of P2, which request was granted
Need = (5, 0 ,1)
Available = (5, 3, 4)
Need <= Available = True
Therefore, again request of P2 is granted. Since the request is granted, change the Available according to the formula:
Available = Available + Allocation
Available = (5, 3, 4) + (4, 0 ,1)
New Available = (9, 3, 5)

7. Then, check the for processes that were not granted.


a) process P3
Need = (7, 3, 3)
Available = (9, 3, 5)
Need <= Available = True
Therefore, request for P3 is granted. Then calculate the NEW AVAILABLE
Available = Available + Allocation
Available = (9, 3, 5) + (0, 2, 0)
New Available = (9, 5, 5)

b) process P0
Need = (3, 2, 1)
Available = (9, 5, 5)
Need <= Available = True
Request of P0 is granted.

Safe Sequence : <P1, P4, P2, P3, P0>


Conclusion:
The total amount of resources will be calculated to each process. Therefore, we can say that the system is in a safe state.

3) To determine the total sum of each type of resource, use the formula below:
Total amount of resources = sum of columns of allocation + available

Allocation Max Available


Processes A B C A B C A B C
P0 1 1 2 4 3 3 2 1 0
P1 2 1 2 3 2 2
P2 4 0 1 9 0 2
P3 0 2 0 7 5 3
P4 1 1 2 1 1 2
Total 8 5 7

Total amount of resources = (8, 5, 7) + (2, 1, 0)


Total amount of resources = (10, 6, 7)
g to the formula:
m is in a safe state.
Allocation Max Available
Processes A B C A B C A B C
P0 1 2 2 3 3 4 1 1 0
P1 2 1 2 2 3 2
P2 3 1 2 9 0 2
P3 2 2 1 7 5 3
P4 2 2 1 2 2 1
P5 3 2 2 5 3 2

Requirements
1. calculate the content of the need matrix
2. check if the system is in a safe state
3. determine the total sum of each type of resource

SOLUTION:
1. The content of the need matrix can be calculated by using the formula given below:
Need
Processes A B C
P0 2 1 2
P1 0 2 0
P2 6 -1 0
P3 5 3 2
P4 0 0 0
P5 2 1 0
1. For process PO

NEED= (2,1,2)
AVAILABLE=(1,1,0)
Need <= Available = False
Therefore, the system will move to the next process.

2. For process P1

NEED= (0,2,0)
AVAILABLE=(1,1,0)
Need <= Available = False
Therefore, the system will move to the next process.

3. For process P2

NEED= (6,-1,0)
AVAILABLE=(1,1,0)
Need <= Available = False
4. For process P3

NEED= (5,3,2)
AVAILABLE=(1,1,0)
Need <= Available = False
Therefore, the system will move to the next process.

5. For process P4

NEED= (0,0,0)
AVAILABLE=(1,1,0) Need <= Available = True
Therefore, request of P4 is granted, if granted Available value will be changed according to the formula below:
Available = Available + Allocation
Available = (1, 1, 0) + (2, 2, 1)
New Available = (3, 3, 1)

6. Now, check again the process of P0, which request was NOT granted
NEED= (2,1,2)
Available = (3,3,1)
Need <= Available = True
Therefore, request of P0 is granted, if granted Available value will be changed according to the formula below:
Available = (3, 3, 1) + (1, 2, 2)
New Available = (4, 5, 3)

7. Now, check again the process of P1, which request was NOT granted
NEED= (0,2,0)
Available = (4,5,3)
Need <= Available = True
Therefore, request of P1 is granted, if granted Available value will be changed according to the formula below:
Available = (4, 5, 3) + (2, 1, 2)
New Available = (6, 6, 5)

8. Now, check again the process of P2, which request was NOT granted
NEED= (6,-1,0)
Available = (6,6,5)
Need <= Available = True
Therefore, request of P2 is granted, if granted Available value will be changed according to the formula below:
Available = (6, 6, 5) + (3, 1, 2)
New Available = (9, 7, 7)
9. Now, check again the process of P3, which request was NOT granted
NEED= (5,3,2)
Available = (9,7,7)
Need <= Available = True
Therefore, request of P3 is granted, if granted Available value will be changed according to the formula below:
Available = (9, 7, 7) + (2, 2, 1)
New Available = (11, 9, 8)

10. For process P5


NEED= (2,1,0)
Available = (11,9,8)
Need <= Available = True

Available = (11, 9, 8) + (3, 2, 2)


New Available = (14, 11, 10)

Request of P5 is granted.

Safe Sequence : <P4, P0, P1, P2, P3,P4,P5>

Allocation Max Available


Processes A B C A B C A B C
P0 1 2 2 3 3 4 1 1 0
P1 2 1 2 2 3 2
P2 3 1 2 9 0 2
P3 2 2 1 7 5 3
P4 2 2 1 2 2 1
P5 3 2 2 5 3 2
total 13 10 10
Total amount of resources = (13, 10, 10) + (2, 1, 0)
Total amount of resources = (15, 11, 10)
ormula below:

ormula below:

ormula below:

ormula below:
ormula below:

You might also like