Skip to content
Official PYQ · 2017

GATE CS 2017 Set 1 Q24 — CPU Scheduling

Explain with AI
Consider the following CPU processes with arrival times (in milliseconds) and length of CPU bursts (in milliseconds) as given below:
ProcessArrival TimeBurst TimeP_107P_233P_355P_462\small \begin{array}{|c|c|c|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time}\\ \hline \text{$P\_1$} & 0 & 7 \\ \hline \text{$P\_2$} & 3 & 3 \\ \hline \text{$P\_3$} & 5 & 5 \\ \hline \text{$P\_4$} & 6 & 2 \\ \hline \end{array}If the pre-emptive shortest remaining time first scheduling algorithm is used to schedule the processes, then the average waiting time across all processes is _____________ milliseconds.
View worked solution

Answer: 3

We use the preemptive Shortest Remaining Time First (SRTF) scheduling algorithm. Let us trace the execution step-by-step using a Gantt chart:

Gantt Chart:

P1P2P4P1P3
03681217

Step-by-step Execution:

  • At t=0t = 0: Only P1P_1 is available. It runs for 3 ms3\text{ ms} (remaining burst time of P1=4P_1 = 4).
  • At t=3t = 3: P2P_2 arrives with burst time 33. Since 3<43 < 4, P2P_2 preempts P1P_1.
  • At t=5t = 5: P3P_3 arrives with burst time 55. The remaining burst time of P2P_2 is 11. Since 1<51 < 5, P2P_2 continues and finishes at t=6t = 6.
  • At t=6t = 6: P4P_4 arrives with burst time 22. The available processes are P1P_1 (remaining 44), P3P_3 (remaining 55), and P4P_4 (remaining 22). P4P_4 is scheduled and finishes at t=8t = 8.
  • At t=8t = 8: Between P1P_1 (remaining 44) and P3P_3 (remaining 55), P1P_1 is scheduled and finishes at t=12t = 12.
  • At t=12t = 12: P3P_3 is scheduled and finishes at t=17t = 17.

Metrics Calculation:

ProcessArrival Time (AT)Burst Time (BT)Completion Time (CT)Turnaround Time (TAT)Waiting Time (WT)P10712125P233630P35517127P462820\begin{array}{|c|c|c|c|c|c|} \hline \textbf{Process} & \textbf{Arrival Time (AT)} & \textbf{Burst Time (BT)} & \textbf{Completion Time (CT)} & \textbf{Turnaround Time (TAT)} & \textbf{Waiting Time (WT)} \\ \hline P_1 & 0 & 7 & 12 & 12 & 5 \\ \hline P_2 & 3 & 3 & 6 & 3 & 0 \\ \hline P_3 & 5 & 5 & 17 & 12 & 7 \\ \hline P_4 & 6 & 2 & 8 & 2 & 0 \\ \hline \end{array}

Average Waiting Time=5+0+7+04=124=3 ms\text{Average Waiting Time} = \frac{5 + 0 + 7 + 0}{4} = \frac{12}{4} = 3\text{ ms}

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

Published
Report a correction
Keep exploringMore CPU Scheduling questions