In: Computer Science
Consider the following snapshot of a system: Allocation Max Available A B C D A B C D A B C D
P0 0 0 1 2 0 0 1 2 1 5 2 0
P1 1 0 0 0 1 7 5 0
P2 1 3 5 4 2 3 5 6
P3 0 6 3 2 0 6 5 2
P4 0 0 1 4 0 6 5 6
Answer the following questions using the banker’s algorithm: a. What is the content of the matrix Need? b. Is the system in a safe state? Demonstrate the reason for your answer. c. If a request from process P1 arrives for (0,4,2,0), can the request be granted immediately? Demonstrate the reason for your answer.
Given:
Allocation:
A | B | C | D | |
P0 | 0 | 0 | 1 | 2 |
P1 | 1 | 0 | 0 | 0 |
P2 | 1 | 3 | 5 | 4 |
P3 | 0 | 6 | 3 | 2 |
P4 | 0 | 0 | 1 | 4 |
Max:
A | B | C | D | |
P0 | 0 | 0 | 1 | 2 |
P1 | 1 | 7 | 5 | 0 |
P2 | 2 | 3 | 5 | 6 |
P3 | 0 | 6 | 5 | 2 |
P4 | 0 | 6 | 5 | 6 |
Available:
A | B | C | D |
1 | 5 | 2 | 0 |
a)
Need matrix is calculated as follows:
Need=Max-Allocation
A | B | C | D | |
P0 | 0 | 0 | 0 | 0 |
P1 | 0 | 7 | 5 | 0 |
P2 | 1 | 0 | 0 | 2 |
P3 | 0 | 0 | 2 | 0 |
P4 | 0 | 6 | 4 | 2 |
b)
To check whether this system is in safe state.
We have available vector as:
Available:
A | B | C | D |
1 | 5 | 2 | 0 |
We can see from the need matrix that process P0 does not need any further resources and therefore, it can complete its execution and release the allocated resources.
Therefore, the available now becomes:
A | B | C | D |
1 | 5 | 3 | 2 |
Now, from the need matrix we can see that process P2 can be given the available resources so that process P2 completes its execution and release the resources allocated to it.
Therefore, the available now becomes:
A | B | C | D |
2 | 8 | 8 | 6 |
Now, from the need matrix it is clear that the remaining processes, P1 P3 P4, can be executed with the current available resources.
After executing Process P1
The available now becomes:
A | B | C | D |
3 | 8 | 8 | 6 |
After executing Process P3
The available now becomes:
A | B | C | D |
3 | 14 | 11 | 8 |
After executing Process P4
The available now becomes:
A | B | C | D |
3 | 14 | 12 | 12 |
Yes, the system is in safe state. The safe sequence is P0 P2 P1 P3 P4.
c)
If the request by P1(0,4,2,0) is approved, then the allocation matrix, need matrix and available will become as follows:
Allocation:
A | B | C | D | |
P0 | 0 | 0 | 1 | 2 |
P1 | 1 | 4 | 2 | 0 |
P2 | 1 | 3 | 5 | 4 |
P3 | 0 | 6 | 3 | 2 |
P4 | 0 | 0 | 1 | 4 |
Need:
A | B | C | D | |
P0 | 0 | 0 | 0 | 0 |
P1 | 0 | 3 | 3 | 0 |
P2 | 1 | 0 | 0 | 2 |
P3 | 0 | 0 | 2 | 0 |
P4 | 0 | 6 | 4 | 2 |
Available:
A | B | C | D |
1 | 1 | 0 | 0 |
P0 does not require any further resources. Therefore, P0 gets executed completely and releases the allocated resources.
Therefore, available becomes;
A | B | C | D |
1 | 1 | 1 | 2 |
Now, P2 can be executed.
Therefore, available becomes:
A | B | C | D |
2 | 4 | 6 | 6 |
Now, P1 can be executed.
Therefore, available becomes:
A | B | C | D |
3 | 8 | 8 | 6 |
Now, both the processes can be executed.
P3 gets executed
Therefore, available becomes:
A | B | C | D |
3 | 14 | 11 | 8 |
P4 gets executed
Therefore, available becomes:
A | B | C | D |
3 | 14 | 12 | 12 |
Therefore, the system remains in safe state with the safe sequence P0 P2 P1 P3 P4.