IAE Academy

GATE 2024 CS2 Q.37: solution and answer

GATE 2024 · CS2Q.37 · 2 marks · MCQ

Consider a single processor system with four processes A, B, C, and D, represented as given below, where for each process the first value is its arrival time, and the second value is its CPU burst time.

A (0, 10), B (2, 6), C (4, 3), and D (6, 7).

Which one of the following options gives the average waiting times when preemptive Shortest Remaining Time First (SRTF) and Non-Preemptive Shortest Job First (NP-SJF) CPU scheduling algorithms are applied to the processes?

  1. (A)

    SRTF = 6, NP-SJF = 7

  2. (B)

    SRTF = 6, NP-SJF = 7.5

  3. (C)

    SRTF = 7, NP-SJF = 7.5

  4. (D)

    SRTF = 7, NP-SJF = 8.5

See the question in the paper

Answer and solution

ANSWER

The average waiting times are SRTF = 6 and NP-SJF = 7.5, which is option (B).

Official answer: BSource: Official answer key, GATE 2024 CS2 (IISc Bengaluru)

  1. Process table: Waiting time completion arrival burst.

  2. SRTF timeline: A runs 0 to 2 (remaining 8). At 2, B arrives with 6, less than 8, so B preempts A and runs 2 to 4 (remaining 4). At 4, C arrives with 3, less than B's remaining 4, so C preempts B.

  3. C runs 4 to 7. D arrives at 6 with 7, but C has 1 left, so C continues and finishes at 7. Remaining times are A 8, B 4, D 7, so B runs 7 to 11, then D runs 11 to 18, then A runs 18 to 26.

  4. SRTF Gantt chart:

  5. SRTF waiting times: , , , . Total , average .

  6. NP-SJF timeline: A starts at 0 and runs to 10 with no preemption. At 10, B (6), C (3) and D (7) are waiting, so the shortest, C, runs 10 to 13, then B (6) runs 13 to 19, then D runs 19 to 26.

  7. NP-SJF waiting times: , , , . Total , average .

  8. So SRTF and NP-SJF , which is option (B).

KEY IDEA

In SRTF, re-decide at every arrival: run the process with the least remaining time, and preempt only if the newcomer's burst is strictly less than the running process's remaining time. In NP-SJF, once a process starts it runs to completion, and the next one is the shortest burst among those waiting.

WATCH OUT FOR

Comparing a newly arrived process with the running process's full burst instead of its remaining time. For example, D (7) arrives at 6 while C has only 1 left, so C must not be preempted. Another slip is forgetting to subtract arrival time when computing waiting time.

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

More CPU scheduling questions