Skip to content
Official PYQ · 2017

GATE CS 2017 Set 2 Q51 — CPU Scheduling

Explain with AI
Consider the set of process with arrival time (in milliseonds), CPU burst time (in millisecods) and priority (00 is the highest priority)  shown below. None of the process have I/O burst timeProcessArrival TimeBurst TimePriorityP_10112P_25280P_31223P_42101P_59164\small \begin{array}{|c|c|c|c|} \hline \textbf{Process} & \textbf{Arrival Time} & \textbf{Burst Time} & \textbf{Priority} \\ \hline \text{$P\_1$} & 0 & 11 & 2 \\ \hline \text{$P\_2$} & 5 & 28 & 0 \\ \hline \text{$P\_3$} & 12 & 2 & 3 \\ \hline \text{$P\_4$} & 2 & 10 & 1\\ \hline \text{$P\_5$} & 9 & 16 & 4 \\ \hline \end{array}The average waiting time (in milli seconds) of all the process using premtive priority scheduling algorithm is ______
View worked solution

Answer: 29

We use the preemptive priority scheduling algorithm where 00 represents the highest priority. Let's trace the execution of the processes chronologically:

  • At t=0t = 0: Only P1P_1 (Priority 2) is available. It starts execution.
  • At t=2t = 2: P4P_4 (Priority 1) arrives. Since P4P_4 has a higher priority than P1P_1, P1P_1 is preempted.
    Remaining burst of P1=9P_1 = 9.
  • At t=5t = 5: P2P_2 (Priority 0) arrives. Since P2P_2 has the highest priority, it preempts P4P_4.
    Remaining burst of P4=7P_4 = 7.
  • At t=5t = 5 to 3333: P2P_2 runs to completion because it has the highest possible priority (00). It finishes at t=33t = 33.
  • At t=33t = 33: Among the ready processes (P1,P3,P4,P5P_1, P_3, P_4, P_5), P4P_4 (Priority 1) is executed next. It finishes at t=33+7=40t = 33 + 7 = 40.
  • At t=40t = 40: Among the remaining processes (P1,P3,P5P_1, P_3, P_5), P1P_1 (Priority 2) is executed. It finishes at t=40+9=49t = 40 + 9 = 49.
  • At t=49t = 49: Between P3P_3 (Priority 3) and P5P_5 (Priority 4), P3P_3 is executed. It finishes at t=49+2=51t = 49 + 2 = 51.
  • At t=51t = 51: P5P_5 is executed. It finishes at t=51+16=67t = 51 + 16 = 67.

We can now construct the scheduling table to find the waiting time (WT=Completion Time−Arrival Time−Burst Time\text{WT} = \text{Completion Time} - \text{Arrival Time} - \text{Burst Time}):

Process Arrival Time (AT) Burst Time (BT) Completion Time (CT) Waiting Time (WT)
P1P_1 0 11 49 49−0−11=3849 - 0 - 11 = 38
P2P_2 5 28 33 33−5−28=033 - 5 - 28 = 0
P3P_3 12 2 51 51−12−2=3751 - 12 - 2 = 37
P4P_4 2 10 40 40−2−10=2840 - 2 - 10 = 28
P5P_5 9 16 67 67−9−16=4267 - 9 - 16 = 42

The average waiting time is calculated as:

Average WT=38+0+37+28+425=1455=29 ms\text{Average WT} = \frac{38 + 0 + 37 + 28 + 42}{5} = \frac{145}{5} = 29 \text{ ms}

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

Published
Report a correction
Keep exploringMore CPU Scheduling questions