Skip to content
Official PYQ · 2014

GATE CS 2014 Set 3 Q32 — CPU Scheduling

Explain with AI

An operating system uses shortest remaining time first scheduling algorithm for pre-emptive scheduling of processes. Consider the following set of processes with their arrival times and CPU burst times (in milliseconds):ProcessArrival TimeBurst TimeP1012P224P336P485\small \begin{array}{|c|c|c|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time}\\ \hline \text{P1} & 0 & 12 \\ \text{P2} & 2 & 4 \\ \text{P3} & 3 & 6 \\ \text{P4} & 8 & 5 \\ \hline \end{array}The average waiting time (in milliseconds) of the processes is ______.

View worked solution

Answer: 5.5

To find the average waiting time using the Shortest Remaining Time First (SRTF) scheduling algorithm, we track the execution of processes step-by-step:

  • At t=0t = 0: Only P1\text{P1} is in the ready queue. It starts execution.
  • At t=2t = 2: P2\text{P2} arrives with a burst time of 44 ms. The remaining burst time of P1\text{P1} is 1010 ms. Since P2\text{P2} has a shorter remaining time (4<104 < 10), P2\text{P2} preempts P1\text{P1}.
  • At t=3t = 3: P3\text{P3} arrives with a burst time of 66 ms. The remaining burst time of P2\text{P2} is 33 ms. Since P2\text{P2} still has the shortest remaining time (3<63 < 6), P2\text{P2} continues.
  • At t=6t = 6: P2\text{P2} finishes execution. The ready queue contains P1\text{P1} (remaining 1010 ms) and P3\text{P3} (remaining 66 ms). P3\text{P3} starts execution.
  • At t=8t = 8: P4\text{P4} arrives with a burst time of 55 ms. The remaining burst time of P3\text{P3} is 44 ms. Since P3\text{P3} has a shorter remaining time (4<54 < 5), P3\text{P3} continues.
  • At t=12t = 12: P3\text{P3} finishes execution. The ready queue contains P4\text{P4} (remaining 55 ms) and P1\text{P1} (remaining 1010 ms). P4\text{P4} starts execution.
  • At t=17t = 17: P4\text{P4} finishes execution. P1\text{P1} resumes and runs to completion.
  • At t=27t = 27: P1\text{P1} finishes execution.

Gantt Chart:

P1P2P3P4P1022661212171727\begin{array}{|c|c|c|c|c|} \hline \text{P1} & \text{P2} & \text{P3} & \text{P4} & \text{P1} \\ \hline 0 \quad\quad 2 & 2 \quad\quad 6 & 6 \quad\quad 12 & 12 \quad\quad 17 & 17 \quad\quad 27 \\ \hline \end{array}

Now, we calculate the Completion Time (CT), Turnaround Time (TAT = CT - AT), and Waiting Time (WT = TAT - BT) for each process:

Process Arrival Time (AT) Burst Time (BT) Completion Time (CT) Turnaround Time (TAT) Waiting Time (WT)
P1 0 12 27 27 15
P2 2 4 6 4 0
P3 3 6 12 9 3
P4 8 5 17 9 4

Average Waiting Time=15+0+3+44=224=5.5 ms\text{Average Waiting Time} = \frac{15 + 0 + 3 + 4}{4} = \frac{22}{4} = 5.5 \text{ ms}

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

Published
Report a correction
Keep exploringMore CPU Scheduling questions