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.
IN TEXT ONLY!!!
Allocated Max
A | B | C | D | A | B | C | D | |||
---|---|---|---|---|---|---|---|---|---|---|
P0 | 0 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | ||
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 |
Available = ( 1 5 2 0 )
a) Need = Max - Allocated
Need
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) Available = 1 5 2 0
P0 allocated = 0 0 1 2 (P0 releases all the resources allocated to it)
Available = 1 5 3 2
P2 allocated = 1 3 5 4
Available = 2 8 8 6
P1 allocated = 1 0 0 0
Available = 3 8 8 6
P3 allocated = 0 6 3 2
Available = 3 14 11 8
P4 allocated = 0 0 1 4
Available =3 14 12 12
All processes are served successfully so System is in a safe state.
c) If P1 is allocated with ( 0 4 2 0 ) then Allocated and need matrices, Available vector will be changed.
Allocated Need
A | B | C | D | A | B | C | D | ||
P0 | 0 | 0 | 1 | 2 | 0 | 0 | 0 | 0 | |
P1 | 1 | 4 | 2 | 0 | 0 | 3 | 3 | 0 | |
P2 | 1 | 3 | 5 | 4 | 1 | 0 | 0 | 2 | |
P3 | 0 | 6 | 3 | 2 | 0 | 0 | 2 | 0 | |
P4 | 0 | 0 | 1 | 4 | 0 | 6 | 4 | 2 |
Available = ( 1 1 0 0 )
P0 allocated = 0 0 1 2
Available = 1 1 1 2
P2 allocated = 1 3 5 4
Avaiable = 2 4 6 6
P1 allocated = 1 4 2 0
Available = 3 8 8 6
P3 allocated = 0 6 3 2
Available = 3 14 11 8
P4 allocated = 0 0 1 4
Avaialable = 3 14 12 12
All processes are served successfully So system is safe if we serve P1. So request can be granted.