I’m trying to learn this material Please write in a way a kid can understand it
ID: 3700182 • Letter: I
Question
I’m trying to learn this material Please write in a way a kid can understand it easily thank u 3. Consider the following snapshot of a system Allocation ABCD 0 0 1 2 0 0 Max ABCD Available ABCD PO Pl P2 P3 P4 2 1 5 20 1 3 5 4 2 3 5 6 0 6 3 2 0 6 5 2 0 0 1 40 6 5 6 Answer the following questions using the banker's algorithm a) How many instances of each resource type does the system have? (5 points) b) What is the content of the matrix Need? Draw the table (5 points) c) Is the system in a safe state? Why? (10 points) d) If a request from process P1 arrives for (0, 4, 2, 0), can the request be granted immediately? Explain why. (Hint: Suppose the request is granted, then is the system safe? If yes, then the request can be granted immediately; else, it cannot be granted. So, for this question, you need to inspect whether the system is safe after the request is granted.) (10 points)Explanation / Answer
Tried my best to explain. Please upvote if you are able to understand
We can see that there are 4 resources in the system A,B,C and D .
There are 5 processes P0, P1, P2, P3 and P4
Allocation matrix shows the different resources allocated to different processes at any instance.
If we do the sum of columns (for A,B,C and D) in allocation matrix then it will give the allocation vector. This vector will show that how many instances of each resource type is busy.
Allocation vector = (2, 9, 10, 12)
So, 2 instances of A, 9 instances of B, 10 instances of C and 12 instances of D are occupied/allocated.
Available matrix shows the free instances of each resources which are not occupied by any process.
Available vector = (1, 5, 2, 0)
a)
When we add allocation and available vector, we get the total instances of each resources present in the system.
Allocation vector + Available vector = Total resources
(2, 9, 10, 12) + (1, 5, 2, 0) = ( 3, 14, 12, 12)
A = 3
B = 14
C = 12
D = 12
b)
Need matrix is the one which shows the number of each resources still needed for each process. We can get this by
maximum resource required – allocated resource
To create this matrix we will subtract each element of allocation matrix from the max matrix
Need [i,j] = Max[i.j] – Allocation[i,j]
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
c)
To see if system is safe or not, we will see the resources needed by each process and the avaialble resources.
First we will see P0.
P0 needs (0 0 0 0) . That means it does not require any resource and can be finished. Since it is finished it will release the resources allocated to it (0, 0, 1, 2). This will get added up in the previous available vector( 1, 5, 2, 0)
So new available vector is (1, 5, 3, 2)
Now come to process P1.
It needs (0, 7, 5, 0) and available is (1, 5, 3, 2)
Since need > available. It cant be executed so it is unsafe.
Now come to process P2.
It needs (1, 0 , 0, 2) and available is (1, 5, 3, 2)
Since available > need , Resources will be allocated and process will be finished.
Available = (1, 5, 3, 2) - (1, 0 , 0, 2) = (0, 5, 3, 0)
and allocated will be allocation vector + need = (1, 3, 5,4) + (1, 0 , 0, 2) = (2,3,5,6)
After finishing it will release all the resources allocated to it
So now available vector is (0, 5, 3, 0) + (2,3,5,6) = (2, 8, 8, 6)
Now come to process P3
It needs (0, 0, 2, 0) and available is (2, 8, 8, 6).
Since availble > needs
Resources will be allocated to it and process will finish.
Available = (2, 8, 8, 6) - (0, 0, 2, 0) = (2, 8, 6, 6)
and allocated will be allocation vector + need = (0, 6, 3, 2) + (0, 0, 2, 0) = (0, 6, 5, 2)
After finishing it will release all the resources allocated to it
So now available vector is (2, 8, 6, 6) + (0, 6, 5, 2) = ( 2, 14, 11, 8)
Now come to process P4.
It needs (0, 6, 4, 2) and available is ( 2, 14, 11, 8)
Since need < available
Resources will be allocated to it and process will finish.
Available = ( 2, 14, 11, 8) - (0, 6, 4, 2) = (2, 8, 7, 6)
and allocated will be allocation vector + need = (0, 0, 1, 4) + (0, 6, 4, 2) = (0, 6, 5, 6)
After finishing it will release all the resources allocated to it
So now available is (0, 6, 5, 6) + (2, 8, 7, 6) = (2, 14, 12, 12)
Now P1 needs (1, 0, 0, 0) and available is (2, 14, 12, 12), so it will get executed successfully.
So system is in a safe state if sequence of execution is P0->P2-> P3-> P4-> P1
d)
P1 required (0, 7, 5, 0) earlier. When it turns came after executing P0, available ector was
(1, 5, 3, 2). And need > available
But if it needs (0, 4, 2, 0). Then
need < available
And request can be granted immediately.
Also process will be executewd sequentially P0->P1->P2->P3->P4
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.