Skip to content
Official PYQ · 2007

GATE CS 2007 Q55 — CPU Scheduling

Explain with AI

An operating system used Shortest Remaining System Time first (SRT) process scheduling algorithm. Consider the arrival times and execution times for the following processes:ProcessExecution TimeArrival TimeP1200P22515P31030P41545\small \begin{array}{|c|c|c|} \hline \textbf{Process} & \textbf{Execution Time} & \textbf{Arrival Time} \\ \hline \text{P1} & 20 & 0 \\ \text{P2} & 25 & 15 \\ \text{P3} & 10 & 30 \\ \text{P4} & 15 & 45 \\ \hline \end{array}What is the total waiting time for process P2P2 ?

Choose one option
View worked solution

Answer: B

We trace the execution using the preemptive Shortest Remaining Time First (SRT) scheduling algorithm:

  • At t=0t = 0: Only P1P1 is available (remaining time = 20). P1P1 starts executing.
  • At t=15t = 15: P2P2 arrives (remaining time = 25). P1P1 has 5 units remaining. Since 5<255 < 25, P1P1 continues and finishes at t=20t = 20.
  • At t=20t = 20: P2P2 starts executing.
  • At t=30t = 30: P3P3 arrives (remaining time = 10). P2P2 has executed for 10 units, leaving 15 units remaining. Since 10<1510 < 15, P3P3 preempts P2P2.
  • At t=40t = 40: P3P3 finishes. P2P2 resumes execution.
  • At t=45t = 45: P4P4 arrives (remaining time = 15). P2P2 has 10 units remaining. Since 10<1510 < 15, P2P2 continues and finishes at t=55t = 55.

The Gantt chart is as follows:

[P1: 0 - 20] → [P2: 20 - 30] → [P3: 30 - 40] → [P2: 40 - 55] → [P4: 55 - 70]

We calculate the waiting time for P2P2:

Waiting Time=Completion Time−Arrival Time−Execution Time\text{Waiting Time} = \text{Completion Time} - \text{Arrival Time} - \text{Execution Time}Waiting Time for P2=55−15−25=15\text{Waiting Time for } P2 = 55 - 15 - 25 = 15

Thus, the total waiting time for process P2P2 is 15.

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

Published
Report a correction
Keep exploringMore CPU Scheduling questions