Ex 07
Ex 07
available = [4]
max = [10, 4, 9, 5]
allocation = [5,2,2,3]
need = [5,3,7,2]
finish = [False, False, False, False]
available = [2]
max = [10, 4, 9, 5]
allocation = [7,2,2,3]
need = [3,2,7,2]
finish = [False, False, False, False]
• At t2, P0 has 7 tapes, P1 has 3 tapes, P2 each has 2 tapes, P3 has 3 tapes
◦ 1 tapes available
◦ Is the system safe with Banker’s algorithm?
available = [1]
max = [10, 4, 9, 5]
allocation = [7,3,2,3]
need = [3,1,7,2]
work = available = [1]
finish = [False, False, False, False]
i = 1, need[1] <= work, (1 <= 1) => work = work + allocation[1] = 1 + 3 = 4,
finish[1] = True
i = 0, need[0] <= work, (3 <= 4) => work = work + allocation[0] = 4 + 7 =
11, finish[0] = True
i = 2, need[2] <= work, (7 <= 11) => work = work + allocation[2] = 11 + 2 =
13, finish[2] = True
i = 3, need[3] <= work, (2 <= 13) => work = work + allocation[3] = 13 + 3 =
16, finish[3] = True
finish = [True, True, True, True] => system is safe
• At t3, P0 has 7 tapes, P1 has 3 tapes, P2 each has 2 tapes, P3 has 4 tapes
◦ 0 tape available
◦ Is the system safe with Banker’s algorithm?
available = [0]
max = [10, 4, 9, 5]
allocation = [7,3,2,4]
need = [3,1,7,0]
work = available = [0]
finish = [False, False, False, False]
Problem 2
• 5 processes: P0 - P4; 3 resource types
◦ A (10 instances), B (5 instances), and C (7 instances)
• At time T0:
Allocation Max Available
A B C A B C A B C
P0 1 1 0 7 5 3 3 3 2
P1 1 0 0 3 2 2
P2 2 0 2 9 0 2
P3 2 1 1 2 2 2
P4 1 0 2 4 3 3
Is the system safe with banker’s algorithm?
available = [3,3,2]
need =[[6,4,3],
[2,2,2],
[7,0,0],
[0,1,1],
[3,3,1]]
i = 1, need[1] <= work, (2,2,2) <= (3,3,2) => work = work + allocation[1] =
(3,3,2) + (1,0,0) = (4,3,2), finish[1] = True
i = 3, need[3] <= work, (0,1,1) <= (4,3,2) => work = work + allocation[3] =
(4,3,2) + (2,1,1) = (6,4,3), finish[3] = True
i = 4, need[4] <= work, (3,3,1) <= (6,4,3) => work = work + allocation[4] =
(6,4,3) + (1,0,2) = (7,4,5), finish[4] = True
i = 0, need[0] <= work, (6,4,3) <= (7,4,5) => work = work + allocation[0] =
(7,4,5) + (1,1,0) = (8,5,5), finish[0] = True
i = 2, need[2] <= work, (7,0,0) <= (8,5,5) => work = work + allocation[2] =
(8,5,5) + (2,0,2) = (10,5,7), finish[2] = True
finish = [True, True, True, True, True] => system is safe
PROBLEM 3
• 5 processes: P0 - P4; 3 resource types
◦ A (10 instances), B (5 instances), and C (7 instances)
Allocation Max Available
A B C A B C A B C
P0 0 1 2 7 5 3 3 3 2
P1 2 0 0 3 2 2
P2 3 0 1 9 0 2
P3 2 1 1 2 2 2
P4 0 0 1 4 3 3
• If P1 requests for (1,0,2) => can it be granted
step 1:
request[1] < need[1], (1,0,2) < (1,2,2) => go to step 2:
step 2:
request[1] < available, (1,0,2) < (3,3,2) => go to step 3
step 3:
allocation[1] = allocation[1] + request[1] = (2,0,0) + (1,0,2) = (3,0,2)
available = available - request[1] = (3,3,2) - (1,0,2) = (2,3,0)
call BanhkerAlogithm
work = available = [2,3,0]
finish = [False, False, False, False, False]
need =[[6,4,1]
[0,2,0]
[6,0,1]
[0,1,1]
[4,3,2]]
i = 1 , need[1] <= work, (0,2,0) <= (2,3,0) => work = work +
allocation[1] = (2,3,0) + (3,0,2) = (5,3,2), finish[1] = True
i = 3, need[3] <= work, (0,1,1) <= (5,3,2) => work = work +
allocation[3] = (5,3,2) + (2,1,1) = (7,4,3), finish[3] = True
i = 4, need[4] <= work, (4,3,2) <= (7,4,3) => work = work +
allocation[4] = (7,4,3) + (0,0,1) = (7,4,4), finish[4] = True
i = 0, need[0] <= work, (6,4,1) <= (7,4,4) => work = work +
allocation[0] = (7,4,4) + (0,1,2) = (7,5,6), finish[0] = True
i = 2, need[2] <= work, (6,0,1) <= (7,5,6) => work = work +
allocation[2] = (7,5,6) + (3,0,1) = (10,5,7), finish[2] = True
finish = [True, True, True, True, True] => system is safe
=> P1's request is granted