37.6k views
0 votes
Let a system allocate resources to processes as long as the system state remains safe with respect to deadlocks. Note that a system state is safe if there is a way to allocate the remaining resources in such a manner as to satisfy the maximum needs of all the processes.

With respect to a resource R, let the system have 10 instances of the resource and let there be five processes P1, P2, P3, P4 and P5 that have maximum needs of 5, 7, 4, 9 and 8 instances of the resource respectively.

Start with a safe state in which P1 is holding no instances, P2, P3 and P4 are holding two instances each and P5 is holding one instance of R. Now, consider each of the following requests. For each request, determine if it can be granted while keeping the system in a safe state. Identify the request that can be granted safely.

A. P1 requesting one instance of R

B. P5 requesting one instance of R

C. P2 requesting two instances of R

D. P4 requesting one instance of R

1 Answer

4 votes

The request that can be granted safely is **B. P5 requesting one instance of R**.

In the initial safe state, the total number of instances of R that are available is 10 - (2 + 2 + 2 + 1) = 1.

If P5 requests one instance of R, the total number of instances of R that are available will be 0.

However, P1, P2, P3, and P4 have maximum needs of 5, 7, 4, and 9 instances of R respectively. Therefore, it is possible to allocate the remaining 0 instances of R to these processes in such a manner as to satisfy their maximum needs.

Therefore, the request that can be granted safely is **B. P5 requesting one instance of R**.

The other requests cannot be granted safely because they would leave the system in an unsafe state. For example, if P1 requests one instance of R, the total number of instances of R that are available will be 1.

However, P2, P3, and P4 have maximum needs of 7, 4, and 9 instances of R respectively. Therefore, it is not possible to allocate the remaining 1 instance of R to these processes in such a manner as to satisfy their maximum needs.

As a result, the system would be in an unsafe state if P1's request was granted. The same is true for the requests of P2 and P4.

User Essie
by
7.6k points