Question

Consider the set of processes with arrival time (in milliseconds), CPU burst time (in milliseconds), and priority (0 is the highest priority) shown below. None of the processes have I/O burst time.

Process Arrival Time Burst Time Priority
P1P_1 0 11 2
P2P_2 5 28 0
P3P_3 12 2 3
P4P_4 2 10 1
P5P_5 9 16 4

The average waiting time (in milliseconds) of all the processes using preemptive priority scheduling algorithm is

Official answer and solution
Official answer
29
From
Official GATE 2017 answer key

Solution

Simulate preemptive priority CPU scheduling using a Gantt chart to track execution intervals and calculate waiting times.

Scheduling policy: Preemptive, priority 0 is highest, priority 4 is lowest.
Trace CPU execution:

  • t=0t = 0: P1P_1 arrives (burst 11, priority 2). P1P_1 runs.
  • t=2t = 2: P4P_4 arrives (burst 10, priority 1). Since priority 1 < 2 (higher priority), P4P_4 preempts P1P_1. Remaining burst of P1=11−2=9P_1 = 11 - 2 = 9. P4P_4 runs.
  • t=5t = 5: P2P_2 arrives (burst 28, priority 0). Since priority 0 is the highest possible, P2P_2 preempts P4P_4. Remaining burst of P4=10−(5−2)=7P_4 = 10 - (5 - 2) = 7. P2P_2 runs.
  • During P2P_2's execution, P5P_5 arrives at t=9t=9 (prio 4) and P3P_3 arrives at t=12t=12 (prio 3). Neither can preempt P2P_2.
  • P2P_2 completes at t=5+28=33t = 5 + 28 = 33.
  • t=33t = 33: Ready processes are P4P_4 (prio 1, rem 7), P1P_1 (prio 2, rem 9), P3P_3 (prio 3, rem 2), P5P_5 (prio 4, rem 16). Highest priority is P4P_4. P4P_4 runs from 33 to 40 and finishes.
  • t=40t = 40: Highest priority is P1P_1 (prio 2). P1P_1 runs from 40 to 49 and finishes.
  • t=49t = 49: Highest priority is P3P_3 (prio 3). P3P_3 runs from 49 to 51 and finishes.
  • t=51t = 51: P5P_5 (prio 4) runs from 51 to 67 and finishes.

Calculate turnaround time (TAT=CT−ATTAT = CT - AT) and waiting time (WT=TAT−BTWT = TAT - BT) for each process:

  • P1P_1: CT=49,AT=0,BT=11  ⟹  TAT=49,WT=49−11=38CT = 49, AT = 0, BT = 11 \implies TAT = 49, WT = 49 - 11 = 38
  • P2P_2: CT=33,AT=5,BT=28  ⟹  TAT=28,WT=28−28=0CT = 33, AT = 5, BT = 28 \implies TAT = 28, WT = 28 - 28 = 0
  • P3P_3: CT=51,AT=12,BT=2  ⟹  TAT=39,WT=39−2=37CT = 51, AT = 12, BT = 2 \implies TAT = 39, WT = 39 - 2 = 37
  • P4P_4: CT=40,AT=2,BT=10  ⟹  TAT=38,WT=38−10=28CT = 40, AT = 2, BT = 10 \implies TAT = 38, WT = 38 - 10 = 28
  • P5P_5: CT=67,AT=9,BT=16  ⟹  TAT=58,WT=58−16=42CT = 67, AT = 9, BT = 16 \implies TAT = 58, WT = 58 - 16 = 42

Sum of waiting times:

∑WT=38+0+37+28+42=145 ms\sum WT = 38 + 0 + 37 + 28 + 42 = 145 \text{ ms}

Average waiting time:

Average WT=1455=29 ms\text{Average WT} = \frac{145}{5} = 29 \text{ ms}
Final answer

29

Common trap

Treating larger numeric values as higher priority instead of 0 being the highest priority.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2017 Computer Science and Information Technology (CS) Session 2
Question
51 of 65, printed as CS Q.51
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.