A certain system has four types of resources A, B, C, and D that can be shared by five processes P1, P2, P3, P4, and P5. The system has these four types of resources: 3 Type A, 14 Type B, 12 Type C, and 12 Type D. The resource requirements and allocation of processes are as follows:
(1) How many various resources are left in the system now?
According to the following table: MAX represents the maximum demand, ALL represents the allocated resources, and NEED represents the resources that are still needed (maximum demand - occupied resources)
MAX | ALL | NEED | ||||||||||
A | B | C | D | A | B | C | D | A | B | C | D | |
p1 | 0 | 0 | 1 | 2 | 0 | 0 | 1 | 2 | 0 | 0 | 0 | 0 |
p2 | 1 | 7 | 5 | 0 | 1 | 0 | 0 | 0 | 0 | 7 | 5 | 0 |
p3 | 2 | 3 | 5 | 6 | 1 | 3 | 5 | 4 | 1 | 0 | 0 | 2 |
p4 | 0 | 6 | 5 | 2 | 0 | 6 | 3 | 2 | 0 | 0 | 2 | 0 |
p5 | 0 | 6 | 5 | 6 | 0 | 0 | 1 | 4 | 0 | 6 | 4 | 2 |
The remaining amount of various resources in the system: the amount of various resources owned by the system - the allocated amount of various resources
得到Avail=A:1 B:5 C:2 D:0
① work represents the remaining resources, select less than 1 from each type of resource in NEED in the above table , the numbers 5, 2, 0, P4, P1 are all satisfied, select P1 below
2 ,3,2) resources, and so on:
work | all | need | work+all | T&F | |||||||||||||
A | B | C | D | A | B | C | D | A | B | C | D | A | B | C | D | ||
P1 | 1 | 5 | 2 | 0 | 0 | 0 | 1 | 2 | 0 | 0 | 0 | 0 | 1 | 5 | 3 | 2 | T |
P4 | 1 | 5 | 3 | 2 | 0 | 6 | 3 | 2 | 0 | 0 | 2 | 0 | 1 | 11 | 6 | 4 | T |
P2 | 1 | 11 | 6 | 4 | 1 | 0 | 0 | 0 | 0 | 7 | 5 | 0 | 2 | 11 | 6 | 4 | T |
P3 | 2 | 11 | 6 | 4 | 1 | 3 | 5 | 4 | 1 | 0 | 0 | 2 | 3 | 14 | 11 | 8 | T |
P5 | 3 | 14 | 11 | 8 | 0 | 0 | 1 | 4 | 0 | 6 | 4 | 2 | 3 | 14 | 12 | 12 | T |
(2) Is the system in a safe state now? Why?
Because a safe sequence such as P1->P4->P2->P3->P5 can be found, the system is in a safe state.
(3) If process P2 now requests 0 resources of type A, 4 resources of type B, 2 resources of type C and 0 resources of type D, can the system satisfy its request? Please explain the reason.
P2:request(A:0,B:4,C:2,D:0)
① Only the following conditions are met before proceeding to the next step:
requestNEED(0,7,5,0)
requestAvail(1,5,2,0)
②
Avail=Avail-request=(1, 5,2,0) - (0,4,2,0) =(1,1,0,0)
NEED=NEED-request=(0,7,5,0) - (0,4,2,0) =(0,3,3,0)
ALL=ALL+request=(1,0,0,0)+(0,4,2,0) = (1,4,2,0)
Then change the new data to P2 in the above table and continue the above steps. If a safe sequence can be obtained, the request can be satisfied. If a safe sequence cannot be obtained, the request cannot be satisfied.