Skip to content
Official PYQ · 2004

GATE CS 2004 Q46 — CPU Scheduling

Explain with AI

Consider the following set of processes, with the arrival times and the CPU-burst times gives in milliseconds.ProcessArrival TimeBurst TimeP105P213P323P441\small \begin{array}{|c|c|c|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time}\\ \hline \text{P1} & 0 & 5\\ \text{P2} & 1 & 3\\ \text{P3} & 2 & 3 \\ \text{P4} & 4 & 1\\ \hline \end{array}What is the average turnaround time for these processes with the preemptive shortest remaining processing time first (SRPT) algorithm?

Choose one option
View worked solution

Answer: A

We can determine the execution order using the preemptive Shortest Remaining Processing Time First (SRPT) scheduling algorithm by tracing the Gantt chart step-by-step:

  • At t=0t = 0: Only P1P_1 is in the ready queue with a remaining burst time of 55. P1P_1 starts executing.
  • At t=1t = 1: P2P_2 arrives with burst time 33. The remaining time for P1P_1 is 44. Since 3<43 < 4, P2P_2 preempts P1P_1.
  • At t=2t = 2: P3P_3 arrives with burst time 33. The remaining time for P2P_2 is 22. Since 2<32 < 3, P2P_2 continues executing.
  • At t=4t = 4: P2P_2 finishes execution. P4P_4 arrives with burst time 11. The remaining times are P1(4)P_1 (4), P3(3)P_3 (3), and P4(1)P_4 (1). P4P_4 has the shortest remaining time and executes.
  • At t=5t = 5: P4P_4 finishes execution. The remaining times are P3(3)P_3 (3) and P1(4)P_1 (4). P3P_3 executes.
  • At t=8t = 8: P3P_3 finishes execution. P1P_1 executes for its remaining 44 units.
  • At t=12t = 12: P1P_1 finishes execution.

The Gantt chart is as follows:

[P1: 0-1] [P2: 1-4] [P4: 4-5] [P3: 5-8] [P1: 8-12]

Now, we calculate the Turnaround Time (TAT=Completion Time−Arrival Time\text{TAT} = \text{Completion Time} - \text{Arrival Time}):

Process Arrival Time (AiA_i) Completion Time (CiC_i) Turnaround Time (TATiTAT_i)
P1P_1 0 12 12−0=1212 - 0 = 12
P2P_2 1 4 4−1=34 - 1 = 3
P3P_3 2 8 8−2=68 - 2 = 6
P4P_4 4 5 5−4=15 - 4 = 1

Average Turnaround Time=12+3+6+14=224=5.50 ms\text{Average Turnaround Time} = \frac{12 + 3 + 6 + 1}{4} = \frac{22}{4} = 5.50\text{ ms}

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

Published
Report a correction
Keep exploringMore CPU Scheduling questions