Skip to main content

Preemptive priority and SRTF Gantt

Short answer

After constructing Gantt charts: preemptive priority yields average waiting time 9.75 ms and average turnaround time17.5 ms; SRTF yields average waiting time9.25 ms and average turnaround time17 ms.

Assume you have the following processes to execute with one processor.

ProcessArrival timeCPU burstPriority
P10103
P2272
P3384
P4561
Priority is defined as 1>2>3>4.
i) Make the Gantt chart of the execution of these processes using preemptive priority and Shortest Remaining Time First algorithm.
ii) Find out turnaround time, waiting time, and their average time of each process.

Priority 1 is highest. Turnaround time = completion − arrival; waiting time = turnaround − burst.

i-a) Preemptive priority

| P1 | P2 | P4 | P2 | P1 | P3 |
0    2    5    11   15   23   31
ProcessArrivalBurstCompletionTurnaroundWaiting
P1010232313
P22715136
P338312820
P4561160

Average waiting time = 39/4 = 9.75; average turnaround time = 70/4 = 17.5

Trace: P1 runs 0-2; P2 (priority 2) arrives and preempts it. P4 (priority 1) arrives at 5 and preempts P2, runs 5-11. Then P2 finishes (11-15), then P1 (15-23) and finally P3 (23-31).

i-b) Shortest Remaining Time First

| P1 | P2 | P4 | P1 | P3 |
0    2    9    15   23   31
ProcessArrivalBurstCompletionTurnaroundWaiting
P1010232313
P227970
P338312820
P45615104

Average waiting time = 37/4 = 9.25; average turnaround time = 68/4 = 17

Trace: P1 (10) runs 0-2; at 2 P2 (7) is shorter than P1's remaining 8, so P2 runs. At 5, P4 (6) vs P2's remaining 4: P2 continues until 9. Then P4 (6) runs 9-15, then P1 (8 left) 15-23, then P3 (8) 23-31.

Comparison

AlgorithmAverage waiting timeAverage turnaround time
Preemptive priority9.7517.5
SRTF9.2517

Answer: Preemptive priority AWT = 9.75, ATAT = 17.5 ms; SRTF AWT = 9.25, ATAT = 17 ms.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 2 questions →