Consider a system with five processes 𝑃0 through 𝑃4 and three resource types…

2014

Consider a system with five processes 𝑃0 through 𝑃4 and three resource types 𝑅1, 𝑅2 and 𝑅3 . Resource type 𝑅1 has 10 instances, 𝑅2 has 5 instances and 𝑅3 has 7 instances. Suppose that at time 𝑇0, the following snapshot of the system has been taken :

 Allocation

         𝑅1         𝑅2          𝑅3

𝑃0     0            1             0

𝑃1     2            0             0

𝑃2     3            0             2

𝑃3     2            1             1

𝑃4     0            2             2

 Max

𝑅1         𝑅2           𝑅3

7            5              3

3            2              2

9            0              2

2            2              2

4            3              3

Available

𝑅1         𝑅2            𝑅3

3             3               2

Assume that now the process 𝑃1 requests one additional instance of type 𝑅1 and two instances of resource type 𝑅3. The state resulting after this allocation will be 

Answer: B. Safe stateAnswer: The system will be in a safe state. Reasoning (Banker's algorithm): Total instances: R1 = 10, R2 = 5, R3 = 7. Initial Allocation matrix (P0..P4): P0…

  1. A.

    Ready state 

  2. B.

    Safe state 

  3. C.

    Blocked state

  4. D.

    Unsafe state 

Attempted by 137 students.

Show answer & explanation

Correct answer: B

Answer: The system will be in a safe state.

Reasoning (Banker's algorithm):

  • Total instances: R1 = 10, R2 = 5, R3 = 7.

  • Initial Allocation matrix (P0..P4):

    P0 (0,1,0), P1 (2,0,0), P2 (3,0,2), P3 (2,1,1), P4 (0,2,2).

  • Max matrix (P0..P4):

    P0 (7,5,3), P1 (3,2,2), P2 (9,0,2), P3 (2,2,2), P4 (4,3,3).

  • Compute Need = Max - Allocation:

    P0 (7,4,3), P1 (1,2,2), P2 (6,0,0), P3 (0,1,1), P4 (4,1,1).

  • Initial Available: (3,3,2). P1 requests (1,0,2).

  • Check request <= Need for P1: (1,0,2) <= (1,2,2) — allowed.

    Check Available >= request: (3,3,2) >= (1,0,2) — allowed.

  • Tentatively grant request: new Available = (3,3,2) - (1,0,2) = (2,3,0). New Allocation for P1 = (3,0,2). New Need for P1 = (0,2,0).

Safety check (find a sequence where each process's need <= current work):

  1. Start with Work = Available = (2,3,0). P1 need (0,2,0) <= Work, so P1 can finish. Release P1 allocation (3,0,2) -> Work becomes (5,3,2).

  2. With Work = (5,3,2), P3 need (0,1,1) <= Work, so P3 finishes. Release (2,1,1) -> Work becomes (7,4,3).

  3. With Work = (7,4,3), P0 need (7,4,3) <= Work, so P0 finishes. Release (0,1,0) -> Work becomes (7,5,3).

  4. With Work = (7,5,3), P2 need (6,0,0) <= Work, so P2 finishes. Release (3,0,2) -> Work becomes (10,5,5).

  5. With Work = (10,5,5), P4 need (4,1,1) <= Work, so P4 finishes. All processes can finish.

Therefore a safe sequence exists (one such sequence is P1 -> P3 -> P0 -> P2 -> P4), so the system is in a safe state after the requested allocation.

Explore the full course: Nta Ugc Net Paper 2

Loading lesson…