0% found this document useful (0 votes)
11 views

Bankers Algorithm

Uploaded by

chandrakantha628
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Bankers Algorithm

Uploaded by

chandrakantha628
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1. Consider the following snapshot of the system.

Banker’s Algo
i)Find the need matrix.
ii)Is the system in a safe state? (safety algorithm)
iii)Can the request made by process P4 (3,3,0) be granted.
iv) Find the total count of resources.
Process Allocation Maximum Available Need(Max-Alloc) Work=Available (3,3,2)
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3 3 2 7 4 3 Finish[i]=False i=0 to 4
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0 Safe Sequence <P1,P3,P4,P0,P2>
P3 2 1 1 2 2 2 0 1 1
P4 0 0 2 4 3 3 4 3 1
Allocated 7 2 5
Available 3 3 2
Total 10 5 7
Need<=Work

P0 7 4 3 <= 3 3 2 No P4 4 3 1<=7 4 3 Yes


Finish[4]=True
Work= 7 4 3+0 0 2=>7 4 5
P1 1 2 2 <= 3 3 2 Yes P0 7 4 3<= 7 4 5 Yes
Finish[1]=True Finish[0]=True
Work = Work+Allocation Work = 7 4 5+0 1 0 =>7 5 5
3 3 2 + 2 0 0 =>5 3 2
P2 6 0 0 <= 5 3 2 No P2 6 0 0<=7 5 5 Yes
Finish[2]=True
Work = 7 5 5+3 0 2 =>10 5 7
P3 0 1 1<= 5 3 2 Yes
Finish[3]=True
Work = 5 3 2 + 2 1 1 =>7 4 3
iii)Can the request made by process P4 (3,3,0) be granted. (Req-Resource alloc algo)
Process Allocation Maximum Available Need Work = Available (0 0 2)
A B C A B C A B C A B C
P0 0 1 0 7 5 3 0 0 2 7 4 3 Finish[i]= False i=0 to 4
P1 2 0 0 3 2 2 1 2 2 Need<= Work
P2 3 0 2 9 0 2 6 0 0 Allocating the req resource by P4 will not result in
P3 2 1 1 2 2 2 0 1 1 safe sequence and system will be in unsafe state. So
P4 3 3 2 4 3 3 1 0 1 the req cannot be granted.
1) Req<=need
3 3 0 <= 4 3 1 Yes (No – Error)
2) Req <= Available
3 3 0<=3 3 2 Yes (No – Process has to wait)
Available = Available – Req Available = 3 3 2 – 3 3 0 =>0 0 2
Need = need – Req need= 4 3 1 – 3 3 0 = 1 0 1
Allocation = Allocation + Req Allocation = 0 0 2 + 3 3 0 =>3 3 2
P0 7 4 3<=0 02 No P3 0 1 1 <=0 02 No

P1 1 2 2 <=0 02 No P4 1 0 1 <=0 02 No

P2 6 0 0 <=0 02 No
2. The operating system consists of 3 resources. The number of instances of each resource type is 10,5,5.
The current allocation state is as shown below.
i)Is the system in safe state?
ii)Can the request made by process P4 (1,0,2) be granted.
iii)Can the request made by process P1 (3,0,2) be granted.
Process Allocation Maximum Available Need(Max-Alloc) Work=Available(3 3 2)
A B C A B C A B C A B C
P0 0 1 0 7 5 3 3(10-7) 3(5-2) 2(5-3) 7 4 3 Finish[i]=False i=0 to 4
P1 2 0 0 3 2 2 1 2 2
P2 3 0 2 9 0 2 6 0 0 <P1
P3 2 1 1 2 2 2 0 1 1
P4 0 0 0 4 3 3 4 3 3
7 2 3
Need<= Work

P0 7 4 3 <= 3 3 2 No

P1 1 2 2 <= 3 3 2 Yes
Finish[1]= True
Work = Work + Allocation
Work= 3 3 2 + 2 0 0 =>5 3 2

You might also like