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 tapes
0 0 1 2 3
4 tapes available
Is the system safe with Banker’s algorithm?
Allocation Max Available Need
P0 5 10 4 5
P1 2 4 2
P2 2 9 7
P3 3 5 2
W=4
i=1
Fi = [F, T, F, F]
W=6
i=0
Fi = [T, T, F, F]
W = 11
i=2
Fi = [T, T, T, F]
W = 13
i=3
Fi = [T, T, T, T]
W = 16
The system is safe with Banker’s algorithm
At t , P has 7 tapes, P and P each has 2 tapes , P has 3 tapes
1 0 1 2 3
2 tapes available
Is the system safe with Banker’s algorithm?
Allocation Max Available Need
P0 7 10 2 3
P1 2 4 2
P2 2 9 7
P3 3 5 2
W = 2
i = 1
Fi = [F, T, F, F]
W = 4
i = 0
Fi = [T, T, F, F]
W = 11
i = 2
Fi = [T, T, T, F]
W = 13
i = 3
Fi = [T, T, T, T]
W = 16
The system is safe with Banker’s algorithm
At t , P has 7 tapes, P has 3 tapes, P each has 2 tapes, P has 3 tapes
2 0 1 2 3
1 tapes available
Is the system safe with Banker’s algorithm?
Allocation Max Available Need
P0 7 10 1 3
P1 3 4 1
P2 2 9 7
P3 3 5 2
W = 1
i = 1
Fi = [F, T, F, F]
W = 4
i = 0
Fi = [T, T, F, F]
W = 11
i = 2
Fi = [T, T, T, F]
W = 13
i = 3
Fi = [T, T, T, T]
W = 16
The system is safe with Banker’s algorithm
At t , P has 7 tapes, P has 3 tapes, P each has 2 tapes, P has 4 tapes
3 0 1 2 3
0 tape available
Is the system safe with Banker’s algorithm?
Allocation Max Available Need
P0 7 10 0 3
P1 3 4 1
P2 2 9 7
P3 4 5 1
N0 > W, N1 > W, N2 > W, N3 > W
The system is not safe with Banker’s algorithm
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 Need
ABC ABC ABC ABC
P0 110 753 332 643
P1 100 322 222
P2 202 902 700
P3 211 222 011
P4 102 433 331
Is the system safe with banker’s algorithm?
i=1
Fi = [F, T, F, F, F]
W=432
i=3
Fi = [F, T, F, T, F]
W=643
i=0
Fi = [T, T, F, T, F]
W=753
i=2
Fi = [T, T, T, T, F]
W=955
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
The system is safe with banker’s algorithm.
PROBLEM 3
5 processes: P - P 3 resource types
0 4;
A (10 instances), B (5 instances), and C (7 instances)
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 332 741
P1 200 322 122
P2 301 902 601
P3 211 222 011
P4 001 433 432
If P1 requests for (1,0,2) => can it be granted?
P1 requests for (1, 0, 2)
R1 (1, 0, 2) < N1(1, 2, 2)
R1 (1, 0, 2) < A (3, 3, 2)
W = (2, 3, 0)
All1 = (3, 0, 2)
N1 = (0, 2, 0)
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 230 741
P1 302 322 020
P2 301 902 601
P3 211 222 011
P4 001 433 432
i=1
Fi = [F, T, F, F, F]
W=532
i=3
Fi = [F, T, F, T, F]
W=743
i=0
Fi = [T, T, F, T, F]
W=755
i=2
Fi = [T, T, T, T, F]
W = 10 5 6
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
Granted
If P4 requests for (1,0,0) => can it be granted?
R4 (1, 0, 0) < N4 (4 3 2)
R4 (1, 0, 0) < Avail (3 3 2)
Avail = 2 3 2
All4 = 1 0 1
N4 = 5 3 2
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 232 741
P1 200 322 122
P2 301 902 601
P3 211 222 011
P4 101 433 532
i=1
Fi = [F, T, F, F, F]
W=432
i=3
Fi = [F, T, F, T, F]
W=643
i=2
Fi = [F, T, T, T, F]
W=944
i=0
Fi = [T, T, T, T, F]
W=956
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
Granted
If P0 requests for (0, 2, 0) => can it be granted?
R0 (0, 2, 0) < N0 (7 4 1)
R0 (0, 2, 0) < Avail (3, 3, 2)
Avail = (3 1 2)
All0 = (0 3 2)
N0 = (7 2 1)
Allocation Max Available Need
ABC ABC ABC ABC
P0 032 753 312 721
P1 200 322 122
P2 301 902 601
P3 211 222 011
P4 001 433 432
i=1
Fi = [F, T, F, F, F]
W=512
i=3
Fi = [F, T, F, T, F]
W=723
i=0
Fi = [T, T, F, T, F]
W=755
i=2
Fi = [T, T, T, T, F]
W = 10 5 6
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
Granted
If P1 requests for (1,0,2) => can it be granted
P1 requests for (1, 0, 2)
R1 (1, 0, 2) < N1(1, 2, 2)
R1 (1, 0, 2) < A (3, 3, 2)
W = (2, 3, 0)
All1 = (3, 0, 2)
N1 = (0, 2, 0)
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 230 741
P1 302 322 020
P2 301 902 601
P3 211 222 011
P4 001 433 432
i=1
Fi = [F, T, F, F, F]
W=532
i=3
Fi = [F, T, F, T, F]
W=743
i=0
Fi = [T, T, F, T, F]
W=755
i=2
Fi = [T, T, T, T, F]
W = 10 5 6
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
Granted
If P1’s request is granted, can the next request for (1,0,0) by P4 be granted?
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 130 741
P1 302 322 020
P2 301 902 601
P3 211 222 011
P4 101 433 332
R4 (1, 0, 0) < N4 (4, 3, 2)
R4 (1, 0, 0) < Avail (2, 3, 0)
Avail = (1 3 0)
All4 = (1, 0, 1)
N4 = (3 3 2)
i=1
Fi = [F, T, F, F, F]
W=432
i=3
Fi = [F, T, F, T, F]
W=643
i=2
Fi = [F, T, T, T, F]
W=944
i=0
Fi = [T, T, T, T, F]
W=956
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
If P1’s request is granted, the next request for (1,0,0) by P4 can be granted
If P1 requests for (1,0,2) => can it be granted
P1 requests for (1, 0, 2)
R1 (1, 0, 2) < N1(1, 2, 2)
R1 (1, 0, 2) < A (3, 3, 2)
W = (2, 3, 0)
All1 = (3, 0, 2)
N1 = (0, 2, 0)
Allocation Max Available Need
ABC ABC ABC ABC
P0 012 753 230 741
P1 302 322 020
P2 301 902 601
P3 211 222 011
P4 001 433 432
i=1
Fi = [F, T, F, F, F]
W=532
i=3
Fi = [F, T, F, T, F]
W=743
i=0
Fi = [T, T, F, T, F]
W=755
i=2
Fi = [T, T, T, T, F]
W = 10 5 6
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
Granted
If P1’s request is granted, can the request for (0,2,0) by P0 be granted?
R0 (0, 2, 0) < N0 (7, 4, 1)
R0 (0, 2, 0) < Avail (2, 3, 0)
Avail = (2 1 0)
All0 = (0 3 2)
N0 = (7 2 1)
Allocation Max Available Need
ABC ABC ABC ABC
P0 032 753 210 721
P1 302 322 020
P2 301 902 601
P3 211 222 011
P4 001 433 432
N0 > W, N1 > W, N2 > W, N3 > W, N4 > W
Unsafe -> Not granted
Restore Avail = 2 3 0, N0 = 7 4 1, All0 = 0 1 2
PROBLEM 4
5 processes: P - P 3 resource types
0 4;
A (10 instances), B (5 instances), and C (7 instances)
At snapshot at time T0
Allocation Request Available
ABC ABC ABC
P0 010 100 431
P1 200 202
P2 203 000
P3 211 100
P4 002 002
Is there a deadlock at T ?
0
Fi = [F, F, F, F, F]
i=0
Fi = [T, F, F, F, F]
W=441
i=1
Fi = [T, T, F, F, F]
W=641
i=2
Fi = [T, T, T, F, F]
W=844
i=3
Fi = [T, T, T, T, F]
W = 10 5 5
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
There is no deadlock at T0.
If P2 request (0, 0, 1), is there a deadlock?
Fi = [F, F, F, F, F]
i=0
Fi = [T, F, F, F, F]
W=441
i=1
Fi = [T, T, F, F, F]
W=641
i=2
Fi = [T, T, T, F, F]
W=844
i=3
Fi = [T, T, T, T, F]
W = 10 5 5
i=4
Fi = [T, T, T, T, T]
W = 10 5 7
If P2 request (0, 0, 1), there is no deadlock.