Consider three CPU intensive processes P1, P2, P3 which require 20, 10 and 30…

2016

Consider three CPU intensive processes P1, P2, P3 which require 20, 10 and 30 units of time, arrive at times 1, 3 and 7 respectively. Suppose operating system is implementing Shortest Remaining Time first (preemptive scheduling) algorithm, then _____ context switches are required (suppose context switch at the beginning of Ready queue and at the end of Ready queue are not counted).

  1. A.

    3

  2. B.

    4

  3. C.

    2

  4. D.

    5

Attempted by 274 students.

Show answer & explanation

Correct answer: A

Answer: 3 context switches.

Step-by-step schedule under Shortest Remaining Time First (SRTF):

  • t = 1: Process P1 arrives (burst 20) and starts running. (Initial dispatch is not counted.)

  • t = 3: Process P2 arrives (burst 10). P1 has 18 remaining, P2 has 10, so CPU preempts P1 and switches to P2. (Context switch #1)

  • t = 7: Process P3 arrives (burst 30). At this moment P2 has 6 remaining, P1 has 18 remaining. P2 is still the shortest, so it continues (no switch).

  • t = 13: P2 finishes. Remaining processes are P1 (18) and P3 (30); P1 is shortest, so the CPU switches to P1. (Context switch #2)

  • t = 31: P1 finishes. Only P3 remains (30), so the CPU switches to P3. (Context switch #3)

  • P3 then runs to completion with no further preemptions. The final completion is not counted as a context switch per the instruction.

Total context switches counted: 3 (at t = 3, 13, and 31).

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

Explore the full course: Mppsc Assistant Professor