Consider four processes P, Q, R, and S scheduled on a CPU as per round robin…

2022

Consider four processes P, Q, R, and S scheduled on a CPU as per round robin algorithm with a time quantum of 4 units. The processes arrive in the order P, Q, R, S, all at time t = 0. There is exactly one context switch from S to Q, exactly one context switch from R to Q, and exactly two context switches from Q to R. There is no context switch from S to P. Switching to a ready process after the termination of another process is also considered a context switch. Which one of the following is NOT possible as CPU burst time (in time units) of these processes?

  1. A.

    P = 4, Q = 10, R = 6, S = 2


  2. B.

    P = 2, Q = 9, R = 5, S = 1

  3. C.

    P = 4, Q = 12, R = 5, S = 4

  4. D.

    P = 3, Q = 7, R = 7, S = 3

Attempted by 129 students.

Show answer & explanation

Correct answer: D

Final answer: P = 3, Q = 7, R = 7, S = 3 is not possible.

Explanation by simulating round-robin with time quantum = 4 (all processes arrive at t = 0 in order P, Q, R, S):

  • P runs from t = 0 to t = 3 and terminates (burst 3).

  • Q runs from t = 3 to t = 7 (uses a full quantum of 4), remaining = 3. CPU then switches from Q to R (this is one Q→R switch).

  • R runs from t = 7 to t = 11 (uses 4), remaining = 3. CPU then switches from R to S (an R→S switch).

  • S runs from t = 11 to t = 14 and terminates (burst 3). After S terminates, the next ready process is Q, so this is one S→Q switch (counts as the required single S→Q).

  • Q resumes from t = 14 to t = 17 (remaining 3) and then terminates. After Q terminates, the CPU switches to R, producing a second Q→R switch.

  • R runs from t = 17 to t = 20 (remaining 3) and terminates. After R terminates there is no ready process to switch to.

Observed context-switch counts from this simulation:

  • S→Q = 1 (matches requirement).

  • Q→R = 2 (matches requirement).

  • R→Q = 0 (does NOT match the required 1).

Because R never transfers control to Q in any valid round-robin progression for these burst times, the required single R→Q switch cannot be obtained. Therefore the burst combination P = 3, Q = 7, R = 7, S = 3 is impossible.

By contrast, the other given burst combinations allow Q and R to alternate with enough remaining quanta to produce one S→Q, one R→Q and two Q→R switches, so they are achievable.

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

Explore the full course: Gate Guidance By Sanchit Sir