Skip to content
Official PYQ · 2006

GATE CS 2006 Q06 — CPU Scheduling

Explain with AI

Consider three CPU-intensive processes, which require 1010, 2020 and 3030 time units and arrive at times 00, 22 and 66, respectively. How many context switches are needed if the operating system implements a shortest remaining time first scheduling algorithm? Do not count the context switches at time zero and at the end.

Choose one option
View worked solution

Answer: B

To find the number of context switches, we trace the execution of the processes using the Shortest Remaining Time First (SRTF) scheduling algorithm, which is a preemptive version of Shortest Job First (SJF).

Let the three processes be P1,P2,P_1, P_2, and P3P_3 with their respective arrival times (AiA_i) and burst times (BiB_i):

  • P1P_1: A1=0A_1 = 0, B1=10B_1 = 10
  • P2P_2: A2=2A_2 = 2, B2=20B_2 = 20
  • P3P_3: A3=6A_3 = 6, B3=30B_3 = 30

Execution Trace:

  1. At t=0t = 0: Only P1P_1 has arrived. P1P_1 starts execution.
    Remaining time: P1=10P_1 = 10.
  2. At t=2t = 2: P2P_2 arrives.
    Remaining times: P1=8P_1 = 8, P2=20P_2 = 20.
    Since P1P_1 has the shorter remaining time (8<208 < 20), P1P_1 continues execution. No context switch occurs.
  3. At t=6t = 6: P3P_3 arrives.
    Remaining times: P1=4P_1 = 4, P2=20P_2 = 20, P3=30P_3 = 30.
    Since P1P_1 still has the shortest remaining time (4<20<304 < 20 < 30), P1P_1 continues execution. No context switch occurs.
  4. At t=10t = 10: P1P_1 finishes execution.
    The scheduler selects the process with the shortest remaining time among the ready processes (P2P_2 and P3P_3).
    Since P2P_2 (2020) is shorter than P3P_3 (3030), P2P_2 is scheduled.
    Context Switch 1: P1→P2P_1 \to P_2.
  5. At t=30t = 30: P2P_2 finishes execution.
    Only P3P_3 remains in the queue, so P3P_3 is scheduled.
    Context Switch 2: P2→P3P_2 \to P_3.
  6. At t=60t = 60: P3P_3 finishes execution.

As specified, we do not count the context switches at time t=0t = 0 (start) and at t=60t = 60 (end). Therefore, the total number of context switches is 2.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore CPU Scheduling questions