An operating system uses the Banker’s algorithm for deadlock avoidance when…

2014

An operating system uses the Banker’s algorithm for deadlock avoidance when managing the allocation of three resource types X, Y, and Z to three processes P0, P1, and P2. The table given below presents the current system state. Here, the Allocation matrix shows the current number of resources of each type allocated to each process and the Max matrix shows the maximum number of resources of each type required by each process during its execution.

There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system is currently in a safe state. Consider the following independent requests for additional resources in the
current state:
REQ1: P0 requests 0 units of X, 0 units of Y and 2 units of Z
REQ2: P1 requests 2 units of X, 0 units of Y and 0 units of Z

image.png

Which one of the following is TRUE?

  1. A.

    Only REQ1 can be permitted.

  2. B.

    Only REQ2 can be permitted.

  3. C.

    Both REQ1 and REQ2 can be permitted.

  4. D.

    Neither REQ1 nor REQ2 can be permitted

Attempted by 125 students.

Show answer & explanation

Correct answer: B

Apply the Banker's algorithm to each independent request to test safety.

Initial available resources: (X, Y, Z) = (3, 2, 2).

Current needs (Max - Allocation):

  • P0: (8, 4, 2)

  • P1: (3, 0, 0)

  • P2: (1, 2, 2)

Check request from P0: (0, 0, 2)

  • If granted, available becomes (3, 2, 0).

  • With (3, 2, 0), P1's need (3, 0, 0) can be satisfied, so P1 can finish and release its allocation (3, 2, 0), making available (6, 4, 0).

  • After that, P2's need (1, 2, 2) cannot be satisfied because Z = 0 is available, and P0 still needs X = 8 while only X = 6 is available. No safe completion sequence exists.

  • Conclusion: P0's request (0, 0, 2) must be denied (unsafe).

Check request from P1: (2, 0, 0)

  • If granted, available becomes (1, 2, 2).

  • P1's need is reduced to (1, 0, 0) after the grant, which is ≤ available (1, 2, 2), so P1 can finish.

  • When P1 finishes it releases its allocation (5, 2, 0), making available (6, 4, 2).

  • Now P2's need (1, 2, 2) ≤ (6, 4, 2), so P2 can finish and release (2, 1, 1), making available (8, 5, 3).

  • Finally P0's need (8, 4, 2) ≤ (8, 5, 3), so P0 can finish. A complete safe sequence exists.

  • Conclusion: P1's request (2, 0, 0) can be permitted (safe).

Overall conclusion: Only the request where the second process asks for (2, 0, 0) can be granted safely. The request where the first process asks for (0, 0, 2) is unsafe and must be denied.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir