CPU Scheduling

GATE CS previous year questions · 3 questions

GATE CS 2025 Set 1 | Question 38

MCQ · 2 marks · −0.66

A computer has two processors, \(M_1\) and \(M_2\). Four processes \(P_1, P_2, P_3, P_4\) with CPU bursts of 20, 16, 25, and 10 milliseconds, respectively, arrive at the same time and these are the only processes in the system. The scheduler uses non-preemptive priority scheduling, with priorities decided as follows:

  • \(M_1\) uses priority of execution for the processes as, \(P_1 \gt P_3 \gt P_2 \gt P_4\), i.e., \(P_1\) and \(P_4\) have highest and lowest priorities, respectively.
  • \(M_2\) uses priority of execution for the processes as, \(P_2 \gt P_3 \gt P_4 \gt P_1\), i.e., \(P_2\) and \(P_1\) have highest and lowest priorities, respectively.

A process \(P_i\) is scheduled to a processor \(M_k\), if the processor is free and no other process \(P_j\) is waiting with higher priority. At any given point of time, a process can be allocated to any one of the free processors without violating the execution priority rules. Ignore the context switch time. What will be the average waiting time of the processes in milliseconds?

Options for GATE CS 2025 Set 1 | Question 38

Explanation

Answer: (A)

Simulate both processors. Whenever a processor becomes free, it takes the waiting process that ranks highest in its own priority list.

  • \(t = 0\): \(M_1\) takes \(P_1\) (runs 0 to 20) and \(M_2\) takes \(P_2\) (runs 0 to 16).
  • \(t = 16\): \(M_2\) is free; \(P_3\) and \(P_4\) are waiting, and \(M_2\) prefers \(P_3\) (runs 16 to 41).
  • \(t = 20\): \(M_1\) is free and only \(P_4\) is left (runs 20 to 30).

All processes arrive at time 0, so each waiting time equals its start time: \(0 + 0 + 16 + 20 = 36\), and the average is \(36 / 4 = 9.00\) ms.

Answer: A

GATE CS 2025 Set 2 | Question 26

MCQ · 1 mark · −0.33

Processes \(P1\), \(P2\), \(P3\), \(P4\) arrive in that order at times 0, 1, 2, and 8 milliseconds respectively, and have execution times of 10, 13, 6, and 9 milliseconds respectively. Shortest Remaining Time First (SRTF) algorithm is used as the CPU scheduling policy. Ignore context switching times.

Which ONE of the following correctly gives the average turnaround time of the four processes in milliseconds?

Options for GATE CS 2025 Set 2 | Question 26

Explanation

Answer: (D)

SRTF always runs the ready process with the least remaining time, re-checking whenever a process arrives.

  • 0–2: \(P1\) runs. At time 1, \(P2\) needs 13 but \(P1\) only 9 more.
  • 2–8: \(P3\) (6) preempts \(P1\) (8 left) and finishes at 8.
  • 8–16: \(P4\) arrives needing 9, but \(P1\) needs only 8, so \(P1\) finishes at 16.
  • 16–25: \(P4\) (9) runs before \(P2\) (13).
  • 25–38: \(P2\) runs.

Turnaround time = completion − arrival: \(P1 = 16\), \(P2 = 37\), \(P3 = 6\), \(P4 = 17\). The average is \((16 + 37 + 6 + 17)/4 = 76/4 = 19\) ms; 37 is only \(P2\)'s turnaround time.

Answer: D

GATE CS 2024 Set 2 | Question 37

MCQ · 2 marks · −0.66

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?

Options for GATE CS 2024 Set 2 | Question 37

Explanation

Answer: (B)

SRTF: A runs 0–2. B (6) preempts A (8 left) and runs 2–4. C (3) preempts B (4 left) and runs 4–7; D arrives at 6 but needs 7, more than C’s last unit. Then B runs 7–11, D 11–18 and A 18–26.

Waiting time = completion − arrival − burst: A \(26 - 0 - 10 = 16\), B \(11 - 2 - 6 = 3\), C \(7 - 4 - 3 = 0\), D \(18 - 6 - 7 = 5\). Average \(= 24/4 = 6\).

NP-SJF: A, alone at time 0, runs 0–10 without interruption. Then the shortest waiting job goes first each time: C 10–13, B 13–19, D 19–26. Waiting times: A 0, C 6, B 11, D 13. Average \(= 30/4 = 7.5\).

Answer: B