Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 19

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

 At t , P has 7 tapes, P and P each has 2 tapes , P has 3 tape


1 0 1 2 3
 2 tapes available
 Is the system safe with Banker’s algorithm?

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

 At t , P has 7 tapes, P has 3 tapes, P each has 2 tapes, P has 3 tape


2 0 1 2 3
 1 tapes available
 Is the system safe with Banker’s algorithm?

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

 At t , P has 7 tapes, P has 3 tapes, P each has 2 tapes, P has 4 tape


3 0 1 2 3
 0 tape available
 Is the system safe with Banker’s algorithm?
Max = [ 10 , 4 , 9 , 5 ]
Allocation = [ 7 , 3 , 2 , 3 ]
Available = [ 0 ]
Need = [ 3 , 1 , 7 , 2 ]
1, Finish = [ F , F , F , F] ; W = [0]
2, No such I exist , go to 4
4, with all i :There is 1 or more Finish[i] != true . Conclusion : system in UnSafe State
Problem 2
 5 processes: P - P 3 resource types
0 4;
 A (10 instances), B (5 instances), and C (7 instances)
 At time T :
0
Allocation Max Available
ABC ABC ABC
P0 110 753 332

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

Need : Allocation Available [ 3 3 2 ]


[ABC]
[ 7 4 1 ] P0 [ 0 1 2 ]
[ 1 2 2 ] P1 [ 2 0 0 ]
[ 6 0 1 ] P2 [ 3 0 1 ]
[ 0 1 1 ] P3 [ 2 1 1 ]
[ 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 ]
 Call Banker’s
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
1, Finish = [ F , F , F , F , F ] ; W = [ 2 , 3 ,0 ]
2, i = 1
3, Finish = [ F , T , F , F , F ] ; W = [ 2 , 5 ,0 ]
2, No such I exist , go to 4
4, P0 , P2, P3 , P4 cannot finish . Conclusion : System is in UnSafe State
5, Recovery :
Available = Available + Request1 = [ 3 , 3 , 2 ]
Allocation[1] = Allocation[1] - Request1 = [ 2 , 0 , 0 ]
Need[1] = Need[1] + Request1 = [ 1 , 2 , 2 ]
Cannot be Granted .

 If P4 requests for (1,0,0) => can it be granted?


Need :
[ABC]
[ 7 4 1 ] P0
[ 1 2 2 ] P1
[ 6 0 1 ] P2
[ 0 1 1 ] P3
[ 4 3 2 ] P4
 Request4 = [ 1 , 0 , 0 ] < Need [4]
 Request4 = [ 1 , 0 , 0 ] < Available
 Available = Available – Request4 = [ 2 , 3 , 2 ]
Allocation[4] = Allocation[4] + Request4 = [ 1 , 0 , 1 ]
Need[4] = Need[4] – Request4 = [ 3 , 3 , 2 ]
 Call Banker’s
Allocation :
[A,B,C]
[ 0 , 1 , 2 ] P0
[ 2 , 0 , 0 ] P1
[ 3 , 0 , 1 ] P2
[ 2 , 1 , 1 ] P3
[ 1 , 0 , 1 ] P4
Need :
[ABC]
[ 7 4 1 ] P0 .
[ 1 2 2 ] P1 .
[ 6 0 1 ] P2 .
[ 0 1 1 ] P3 .
[ 3 3 2 ] P4 .
1, Finish = [ F , F , F , F , F ] ; W = [ 2 , 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 = 4
3, Finish = [ F , T , F , T , T ] ; W = [ 7 , 4 ,4 ]
2, i = 0
3, Finish = [ T , T , F , T , T ] ; W = [ 7 , 5 ,6 ]
2, i = 2
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 is in Safe State
Can be Granted .
 If P0 requests for (0, 2, 0) => can it be granted?

 Need : Allocation Available [ 3 3 2 ]


 [ABC]
 [ 7 4 1 ] P0 [ 0 1 2 ]
 [ 1 2 2 ] P1 [ 2 0 0 ]
 [ 6 0 1 ] P2 [ 3 0 1 ]
 [ 0 1 1 ] P3 [ 2 1 1 ]
 [ 4 3 2 ] P4 [ 0 0 1 ]
 Request0 = [ 0 , 2 , 0 ] < Need [0]
 Request0 = [ 0 , 2 , 0 ] < Available
 Available = Available – Request0 = [ 3 , 1 , 2 ]
Allocation[0] = Allocation[0] + Request0 = [ 0 , 3 , 2 ]
Need[0] = Need[0] – Request0 = [ 7 , 2 , 1 ]
Allocation :
[A,B,C]
[ 0 , 1 , 2 ] P0
[ 2 , 0 , 0 ] P1
[ 3 , 0 , 1 ] P2
[ 2 , 1 , 1 ] P3
[ 1 , 0 , 1 ] P4
Need :
[ABC]
[ 7 2 1 ] P0 .
[ 1 2 2 ] P1 .
[ 6 0 1 ] P2 .
[ 0 1 1 ] P3 .
[ 4 3 2 ] P4
1, Finish = [ F , F , F , F , F ] ; W = [ 3 , 1 ,2 ]
2, i = 1
3, Finish = [ F , T , F , F , F ] ; W = [ 5 , 1 ,2 ]
2, i = 3
3, Finish = [ F , T , F , T , F ] ; W = [ 7 , 2 ,3 ]
2, i = 0
3, Finish = [ T , T , F , T , F ] ; W = [ 7 , 3 ,5 ]
2, i = 2
3, Finish = [ T , T , T , T , F ] ; W = [ 10 , 3 ,6]
2, i = 4
3, Finish = [ T , T , T , T , T ] ; W = [ 11 , 3 ,7 ]
2, No such I exist , go to 4
4, With all I : Finish[i] == true. Conclusion : System is in Safe State
Can be Granted .

 If P1 requests for (1,0,2) => can it be granted


 If P1’s request is granted, can the next request for (1,0,0) by P4 be granted?

Need : Allocation Available [ 3 3 2 ]


[ABC]
[ 7 4 1 ] P0 [ 0 1 2 ]
[ 1 2 2 ] P1 [ 2 0 0 ]
[ 6 0 1 ] P2 [ 3 0 1 ]
[ 0 1 1 ] P3 [ 2 1 1 ]
[ 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 ]
 Call Banker’s
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 ]
***** If Granted :
 Request4 = [ 1 , 0 , 0 ] < Need [4]
 Request4 = [ 1 , 0 , 0 ] < Available
 Available = Available – Request4 = [ 1 , 3 , 0 ]
Allocation[4] = Allocation[4] + Request4 = [ 1 , 0 , 1 ]
Need[4] = Need[4] – Request4 = [ 3 , 3 , 2 ]
 Call Banker’s
 [A,B,C]
 [ 0 , 1 , 2 ] P0
 [ 3 , 0 , 2 ] P1
 [ 3 , 0 , 1 ] P2
 [ 2 , 1 , 1 ] P3
 [ 1 , 0 , 1 ] P4
 Need :
 [ABC]
 [ 7 4 1 ] P0
 [ 0 2 0 ] P1 .
 [ 6 0 1 ] P2
 [ 0 1 1 ] P3
 [ 3 3 2 ] P4 Avai [ 1 3 0 ]

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 .

You might also like