IAE Academy

GATE 2022 CS Q.42: solution and answer

GATE 2022 · CSQ.42 · 2 marks · MCQ

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 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

See the question in the paper

Answer and solution

ANSWER

Option (D) is the one that is NOT possible.

Official answer: DSource: Official answer key, GATE 2022 CS (IIT Kharagpur)

  1. All four processes arrive at in the order . In each round every unfinished process runs for units. A switch is counted between consecutive CPU slices, including the switch to the next ready process after a process terminates.

  2. The required switch counts are: exactly once, exactly once, exactly twice, and no .

  3. Option A (): P finishes in round 1. Q runs 4 (6 left), R runs 4 (2 left), S runs 2 and finishes. Round 2: Q runs 4 (2 left), R runs 2 and finishes, Q runs 2 and finishes. Order: . Counts: once, twice, once, no . Possible.

  4. Option B (): P finishes. Q runs 4 (5 left), R runs 4 (1 left), S runs 1 and finishes. Then Q runs 4 (1 left), R runs 1 and finishes, Q runs 1 and finishes. Order: , with the same counts as A. Possible.

  5. Option C (): P finishes. Q runs 4 (8 left), R runs 4 (1 left), S runs 4 and finishes. Then Q runs 4 (4 left), R runs 1 and finishes, Q runs 4 and finishes. Order: , with the same counts as A. Possible.

  6. Option D (): P finishes in round 1. Q runs 4 (3 left), R runs 4 (3 left), S runs 3 and finishes. Round 2: Q runs 3 and finishes, then R runs 3 and finishes. Order: .

  7. In D, occurs once and occurs twice, but Q finishes before R in round 2, so no switch ever occurs. The condition of exactly one switch fails, so D is not possible. The answer is D.

KEY IDEA

Simulate round robin with quantum 4, write the order of CPU slices, and count the adjacent pairs. The required switches ( once, once, twice) need the order . That means P and S end in round 1, Q needs three slices and R needs two slices, and R finishes before Q.

WATCH OUT FOR

Forgetting that the move to the next ready process after a termination counts as a context switch. Another slip is checking only and in option D and missing that never occurs, because Q finishes in round 2 before R gets its second slice.

From the GATE 2022 CS paper. Every question of this paper · Download the full paper · All 8 CPU scheduling questions, with notes

More CPU scheduling questions