In a system, there are three types of resources: E, F and G. Four processes…

2018

In a system, there are three types of resources: E, F and G. Four processes P0, P1, P2and Pexecute concurrently. At the outset, the processes have declared their maximum resource requirements using a matrix named Max as given below. For example, Max[P2,F] is the maximum number of instances of F that Pwould require. The number of instances of the resources allocated to the various processes at any given state is given by a matrix named Allocation.

Consider a state of the system with the Allocation matrix as shown below, and in which 3 instances of E and 3 instances of F are the only resources available.

From the perspective of deadlock avoidance, which one of the following is true?

  1. A.

    The system is in safe state.

  2. B.

    The system is not in safe state, but would be safe if one more instance of E were available.

  3. C.

    The system is not in safe state, but would be safe if one more instance of F were available.

  4. D.

    The system is not in safe state, but would be safe if one more instance of G were available.

Attempted by 108 students.

Show answer & explanation

Correct answer: A

Compute Need = Max - Allocation.

  • P0 needs (E=3, F=3, G=0).

  • P1 needs (E=1, F=0, G=2).

  • P2 needs (E=0, F=3, G=0).

  • P3 needs (E=3, F=4, G=1).

Initial available resources: (E=3, F=3, G=0).

Find a process whose need is <= available, let it finish, add its allocation to available, and repeat to build a safe sequence.

  1. Choose P0 since its need (3,3,0) <= available (3,3,0). After P0 finishes it releases its allocation (1,0,1). New available = (4,3,1).

  2. Choose P2 since its need (0,3,0) <= available (4,3,1). After P2 finishes it releases (1,0,3). New available = (5,3,4).

  3. Choose P1 since its need (1,0,2) <= available (5,3,4). After P1 finishes it releases (1,1,2). New available = (6,4,6).

  4. Finally P3's need (3,4,1) <= available (6,4,6), so P3 can finish.

All processes can finish in this order, therefore the system is in a safe state. One safe sequence is: P0 → P2 → P1 → P3.

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

Explore the full course: Gate Guidance By Sanchit Sir