Professional Documents
Culture Documents
Chapter 4-Problems
Chapter 4-Problems
Problem 1.
A system has 16 tapes, and 4 processes P , P , P , P with corresponding requests:
0 1 2 3
P0 requests at most 10 tapes
P1 requests at most 4 tapes
P2 requests at most 9 tapes
P3 requests at most 5 tapes
At t , P has 5 tapes, P and P each has 2 tapes , P has 3 tape
0 0 1 2 3
4 tapes available
Is the system safe with Banker’s algorithm?
Max = [ 10 , 4 , 9 , 5 ]
Allocation = [ 5 , 2 , 2 , 3 ]
Available = [ 4 ]
Need = [ 5 , 2 , 7 , 2 ]
1, Finish = [ F , F , F , F] ; W = [4]
2, i = 1
3, Finish = [ F , T , F , F ] ; W = [6]
2, i = 0
3, Finish = [ T , T , F , F ] ; W = [11]
2, i = 2
3, Finish = [ T , T , T , F ] ; W = [13]
2, i = 3
3, Finish = [ T , T , T , T ] ; W = [16]
2, No such I exist , go to 4
4, with all i : Finish[i] == true . Conclusion : system in Safe State
Max = [ 10 , 4 , 9 , 5 ]
Allocation = [ 7 , 2 , 2 , 3 ]
Available = [ 2 ]
Need = [ 3 , 2 , 7 , 2 ]
1, Finish = [ F , F , F , F] ; W = [2]
2, i = 1
3, Finish = [ F , T , F , F ] ; W = [4]
2, i = 3
3, Finish = [ F , T , F , T ] ; W = [7]
2, i = 0
3, Finish = [ T , T , F , T ] ; W = [14]
2, i = 2
3, Finish = [ T , T , T , T ] ; W = [20]
2, No such I exist , go to 4
4, with all i : Finish[i] == true . Conclusion : system in Safe State
Max = [ 10 , 4 , 9 , 5 ]
Allocation = [ 7 , 3 , 2 , 3 ]
Available = [ 1 ]
Need = [ 3 , 1 , 7 , 2 ]
1, Finish = [ F , F , F , F] ; W = []
2, i = 1
3, Finish = [ F , T , F , F] ; W = [4]
2, i = 0
3, Finish = [ T , T , F , F] ; W = [11]
2, i = 2
3, Finish = [ T , T , T , F] ; W = [13]
2, i =
3, Finish = [ T , T , T , T] ; W = [16]
2, No such I exist , go to 4
4, with all i : Finish[i] == true . Conclusion : system in Safe State
P1 100 322
P2 202 902
P3 211 222
P4 102 433
Is the system safe with banker’s algorithm?
Need :
[ABC]
[ 6 4 3 ] P0
[ 2 2 2 ] P1
[ 7 0 0 ] P2
[ 0 1 1 ] P3
[ 3 3 1 ] P4
1, Finish = [ F , F , F , F , F ] ; W = [ 3 , 3 ,2 ]
2, i = 1
3, Finish = [ F , T , F , F , F ] ; W = [ 4 , 3 ,2 ]
2, i = 3
3, Finish = [ F , T , F , T , F ] ; W = [ 6 , 4 ,3 ]
2, i = 0
3, Finish = [ T , T , F , T , F ] ; W = [ 7 , 5 ,3 ]
2, i = 2
3, Finish = [ T , T , T , T , F ] ; W = [ 9 , 5 ,5 ]
2, i = 4
3, Finish = [ T , T , T , T , T ] ; W = [ 10 , 5 ,7 ]
2, No such I exist , go to 4
4, with all i : Finish[i] == true . Conclusion : system in Safe State
PROBLEM 3
5 processes: P - P 3 resource types
0 4;
A (10 instances), B (5 instances), and C (7 instances)
Allocation Max Available
ABC ABC ABC
P0 012 753 332
P1 200 322
P2 301 902
P3 211 222
P4 001 433
If P1 requests for (1,0,2) => can it be granted
1, Finish = [ F , F , F , F , F ] ; W = [ 1 , 3 ,0 ]
2, i = 1
3, Finish = [ F , T , F , F , F ] ; W = [ 4 , 3 ,2 ]
2, i = 3
3, Finish = [ F , T , F , T , F ] ; W = [ 6 , 3 ,2 ]
2, No such I exist , go to 4
4, P0 , P2, P3 , P4 cannot finish . Conclusion : System is in UnSafe State
Cannot be Granted .
If P1 requests for (1,0,2) => can it be granted
If P1’s request is granted, can the request for (0,2,0) by P0 be granted?
Need : Allocation Available [ 3 3 2 ]
[ABC]
[ 7 4 1 ] P0 [012]
[ 1 2 2 ] P1 [200]
[ 6 0 1 ] P2 [301]
[ 0 1 1 ] P3 [211]
[ 4 3 2 ] P4 [ 0 0 1 ]
Request1 = [ 1 , 0 , 2 ] < Need [1]
Request1 = [ 1 , 0 , 2 ] < Available
Available = Available – Request1 = [ 2 , 3 , 0 ]
Allocation[1] = Allocation[1] + Request1 = [ 3 , 0 , 2 ]
Need[1] = Need[1] – Request1 = [ 0 , 2 , 0 ]
***** If Granted :
Allocation :
[A,B,C]
[ 0 , 1 , 2 ] P0
[ 3 , 0 , 2 ] P1
[ 3 , 0 , 1 ] P2
[ 2 , 1 , 1 ] P3
[ 0 , 0 , 1 ] P4
Need :
[ABC]
[ 7 4 1 ] P0
[ 0 2 0 ] P1
[ 6 0 1 ] P2
[ 0 1 1 ] P3
[ 4 3 2 ] P4 Avai : [ 2 3 0 ]
Request0 = [ 0 , 2 , 0 ] < Need [0]
Request0 = [ 0 , 2 , 0 ] < Available
Available = Available – Request0 = [ 2 , 1 , 0 ]
Allocation[0] = Allocation[0] + Request0 = [ 0 , 3 , 2 ]
Need[0] = Need[0] – Request0 = [ 7 , 2 , 1 ]
Call Banker’s
Allocation :
[A,B,C]
[ 0 , 3 , 2 ] P0
[ 3 , 0 , 2 ] P1
[ 3 , 0 , 1 ] P2
[ 2 , 1 , 1 ] P3
[ 0 , 0 , 1 ] P4
Need :
[ABC]
[ 7 2 1 ] P0
[ 0 2 0 ] P1
[ 6 0 1 ] P2
[ 0 1 1 ] P3
[ 4 3 2 ] P4 Avai : [ 2 1 0 ]
1, Finish = [ F , F , F , F , F ] ; W = [ 2 , 1 ,0 ]
2, No such I exist , go to 4
4, P0 , P1 ,P2, P3 , P4 cannot finish . Conclusion : System is in UnSafe State
Cannot be Granted .