Banker

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 7

Bankers Algorithm

5 processes P0 through P4 5 P0 P4,


P0,P1,P2,P3,P4
3 resource types A(10instances),B(5 instances), and C (7 instances)
ABCA 10 B 5 C 7
Snapshot at time T0 T0

P0
P1
P2
P3
P4

Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2

Max
A B
7 5
3 2
9 0
2 2
4 3

C
3
2
2
2
3

Available
A B C
3 3 2

MAX P0 MAX A7,B5,C3


0 7,5,3,

Allocation P A7,B
5,C3.
Available
3,3,2
Need
Need
Allocation
Max
Need
A B C
A B C
A B C
P0
0 1 0
7 5 3
7 4 3
P1
2 0 0
3 2 2
P2
3 0 2
9 0 2
P3
2 1 1
2 2 2
P4
0 0 2
4 3 3
p0 po Max A=7,B=5,C=3,
P0 AllocationA=0,B=1,C=0 need max

p1-7

allocationneed A7-07B5-14C3-03
P1P2P3P4
Allocation
Max
Need
A B C
A B C
A B C
P0
0 1 0
7 5 3
7 4 3
P1
2 0 0
3 2 2
1 2 2
P2
3 0 2
9 0 2
6 0 0
P3
2 1 1
2 2 2
0 1 1
P4
0 0 2
4 3 3
4 3 1
available
available
need available
1
P0
P1
P2
P3
P4

Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2

Max
A
7
3
9
2
4

B
5
2
0
2
3

C
3
2
2
2
3

Available
A B C
3 3 2

Need
A B
7 4
1 2
6 0
0 1
4 3

C
3
2
0
1
1

availableA3B3C2
need p1 p3 available
p1 p3 p1
2
P0
P1
P2
P3
P4

Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2

Max
A
7
3
9
2
4

B
5
2
0
2
3

C
3
2
2
2
3

Available
A B C
3 3 2
5 3 2

Need
A B
7 4
1 2
6 0
0 1
4 3

C
3
2
0
1
1

p1 allocation
available
Available Available p1allocationA=3+2=5,B=3+03,C=2+02
3
Allocation
Max
Available
Need
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
1 P1 2 0 0
3 2 2
5 3 2
1 2 2
P2 3 0 2
9 0 2
7 4 3
6 0 0
2 P3 2 1 1
2 2 2
0 1 1
P4 0 0 2
4 3 3
4 3 1

p2-7

p1 available
A5B3C2 NEED 532
P3 P3 P3
P3 Allocation
available A2+57B1+34C1+23
4
Allocation
Max
Available
Need
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
1 P1 2 0 0
3 2 2
5 3 2
1 2 2
P2 3 0 2
9 0 2
7 4 3
6 0 0
2 P3 2 1 1
2 2 2
7 4 5
0 1 1
3 P4 0 0 2
4 3 3
4 3 1
P1P3 available 743 NEED
743 P4 431
P4 P4 002 P4
allocation available available p4 allocation
743+002745
5
Allocation
Max
A B C
A B C
4 P0 0 1 0
7 5 3
1 P1 2 0 0
3 2 2
P2 3 0 2
9 0 2
2 P3 2 1 1
2 2 2
3 P4 0 0 2
4 3 3

Available
A B C
3 3 2
5 3 2
7 4 3
7 4 5
7 5 5

Need
A B
7 4
1 2
6 0
0 1
4 3

C
3
2
0
1
1

P1,P3,P4, available 745 p0


p2 p0

p0 p0 010 availdable
745+010755
6
Allocation
A B C
0 1 0
2 0 0
3 0 2
2 1 1
0 0 2

Max
A
7
3
9
2
4

Available
Need
A B C
A B C
4 P0
3 3 2
7 4 3
1 P1
5 3 2
1 2 2
5 P2
7 4 3
6 0 0
2 P3
7 4 5
0 1 1
3 P4
7 5 5
4 3 1
10 5 7
P1P3P4P0, Available 755
p3-7

B
5
2
0
2
3

C
3
2
2
2
3

p2 p2
allocation302 available
755+3021057
available
3 resource types A(10instances),B(5 instances), and C (7 instances)
ABCA 10 B 5 C 7

a safe state since the sequence


<P1P3P4P0P2>satisfies safety criteria.
8-26 8-27

8-26
Check that Request<=Available(that is ,(1,0,2)<=(3,3,2)=>true
Allocation
Need
Available
A B C
A B C
A B C
P0 0 1 0
7 4 3
2 3 0
P1 3 0 2
0 2 0
P2 3 0 1
6 0 0
P3 2 1 1
0 1 1
P4 0 0 2
4 3 1

4
1
5

P0
P1
P2

Allocation
A B C
0 1 0
3 0 2
3 0 1

Need
A B
7 4
0 2
6 0
p4-7

C
3
0
0

Available
A B C
2
3 0
5
3 2
7
4 3

2
3

P3
P4

2
0

1
0

1
2

0
4

1
3

1
1

7
7
10

4
5
5

5
5
6

1. P1P3P4P0P2

2.Can request for(3,3,0) by P4 be granted?


P4 3,3,0
available
3.Can request for (0,2,0) by P0 be granted?
P0 (0,2,0) 0

Allocation
Need
Available
A B C
A B C
A B C
P0 0 3 0
7 2 3
2
1 0
P1 3 0 2
0 2 0
P2 3 0 1
6 0 0
P3 2 1 1
0 1 1
P4 0 0 2
4 3 1
8-35
Five processes P0 through P4; three resource types A(7 instances),B(2 instances),and
C(6 instances).
Snapshot at time T0:
Allocation
Request
Available
A B C
A B C
A B C
P0 0 1 0
0 0 0
0
0 0
P1 2 0 0
2 0 2
P2 3 0 3
0 0 0
P3 2 1 1
1 0 0
P4 0 0 2
0 0 2

1
5
2
3
4

P0
P1
P2
P3
P4

Allocation
A B C
0 1 0
2 0 0
3 0 3
2 1 1
0 0 2

Request
A B C
0 0 0
2 0 2
0 0 0
1 0 0
0 0 2
p5-7

Available
A B C
0
0 0
0
1 0
3
1 3
5
2 4
5
2 6

P0P2P3P4P1
( P0P2P3P1P4 )

145
Consider the following snapshot of a system:

P0
P1
P2
P3
P4

Allocation
A B C D
0 0 1 2
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4

A
0
1
2
0
0

Max
B C
0 1
7 5
3 5
6 5
6 5

D
2
0
6
2
6

Available
A B C D
1 5 2 0

Answer the following questions using the bankers algorithm:


a.What is the content of the martrix Need?( NEED )
b.Is the system in a safe state?
c.If a request from process P1 arrives for (0,4,2,0),can the request be granted
immediately? P1 0,4,2,0,

ANEEDMAXALLOCATION

P0
P1
P2
P3
P4

Allocation
A B C D
0 0 1 2
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4

A
0
1
2
0
0

Max
B C
0 1
7 5
3 5
6 5
6 5

D
2
0
6
2
6

p6-7

Available
A B C D
1 5 2 0

Need
A B C
0 0 0
0 7 5
1 0 0
0 0 2
0 6 4

D
0
0
2
0
2

B
1
5
2
3
4

P0
P1
P2
P3
P4

Allocation
A B C D
0 0 1 2
1 0 0 0
1 3 5 4
0 6 3 2
0 0 1 4

A
0
1
2
0
0

Max
B C
0 1
7 5
3 5
6 5
6 5

D
2
0
6
2
6

A
1
1
2
2
2
3

Available
B C D
5 2 0
5 3 2
8 8 6
14 11 8
14 12 12
14 12 12

P0P2P3P4P1
C
Allocation
Max
Available
A B C D
A B C D A B C D
1 P0 0 0 1 2
0 0 1 2
1 1 0 0
5 P1 1 4 2 0
1 7 5 0
1 1 1 2
2 P2 1 3 5 4
2 3 5 6
2 4 6 6
3 P3 0 6 3 2
0 6 5 2
2 10 9 8
4 P4 0 0 1 4
0 6 5 6
2 10 10 12
3 14 12 12

0932303800

p7-7

Need
A B C
0 0 0
0 7 5
1 0 0
0 0 2
0 6 4

D
0
0
2
0
2

Need
A B C
0 0 0
0 3 3
1 0 0
0 0 2
0 6 4

D
0
0
2
0
2

You might also like