- 2072 Magh · 5 marks
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.
| Process | Arrival time | CPU burst | Priority |
|---|---|---|---|
| P1 | 0 | 10 | 3 |
| P2 | 2 | 7 | 2 |
| P3 | 3 | 8 | 4 |
| P4 | 5 | 6 | 1 |
| 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
| Process | Arrival | Burst | Completion | Turnaround | Waiting |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 23 | 23 | 13 |
| P2 | 2 | 7 | 15 | 13 | 6 |
| P3 | 3 | 8 | 31 | 28 | 20 |
| P4 | 5 | 6 | 11 | 6 | 0 |
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
| Process | Arrival | Burst | Completion | Turnaround | Waiting |
|---|---|---|---|---|---|
| P1 | 0 | 10 | 23 | 23 | 13 |
| P2 | 2 | 7 | 9 | 7 | 0 |
| P3 | 3 | 8 | 31 | 28 | 20 |
| P4 | 5 | 6 | 15 | 10 | 4 |
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
| Algorithm | Average waiting time | Average turnaround time |
|---|---|---|
| Preemptive priority | 9.75 | 17.5 |
| SRTF | 9.25 | 17 |
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)
Related questions
- FCFS, SJF, Priority, RR Gantt; max AWT · Operating System, chapter 2
- RR, preemptive priority, preemptive SJF · Operating System, chapter 2
- CPU criteria; RR Gantt and times · Operating System, chapter 2
- Real-time scheduling; two-processor numerical · Operating System, chapter 2
- Context switching, 5-state model, MLFQ · Operating System, chapter 2
- FCFS, SJF, RR Gantt and turnaround · Operating System, chapter 2
- Preemptive priority scheduling with P4 (6 ms) · Embedded System, chapter 6 · asked 2×
- Non-preemptive priority scheduling (10, 5, 7 ms) · Embedded System, chapter 6 · asked 2×
- Preemptive priority scheduling (4, 10, 5 ms) · Embedded System, chapter 6 · asked 2×
- Priority and SJF scheduling with P4 and P5 · Embedded System, chapter 6 · asked 2×