---
title: "Preemptive priority and SRTF Gantt"
subject: "Operating System"
chapter: 2
key: "semester_6/operating_system:preemptive-priority-srtf-gantt"
source: https://www.bctengineer.com/q/semester_6/operating_system/preemptive-priority-srtf-gantt
site: BCT Engineering
---

# Preemptive priority and SRTF Gantt

Operating System · Chapter 2: Process Management

- Asked in: 2072 Magh, 5 marks
- Video: [Shortest Remaining Time First(SRTF) Scheduling Algorithm with Example | Operating System](https://www.youtube.com/watch?v=_QcX99B-zbU) — Jenny's Lectures CS IT
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/preemptive-priority-srtf-gantt
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-2

## Question

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.

## 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.

## Answer

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

**i-a) Preemptive priority**

```text
| 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**

```text
| 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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. At t=5, what happens when P4 (priority 1) arrives while P2 (priority 2) runs?
   A. P2 continues until it finishes
   B. P4 preempts P2 and runs 5-11
   C. P4 waits until P1 finishes
   D. P2 and P4 share the CPU
   Answer: B. Priority 1 is highest, so P4 preempts P2 and runs to completion at 11. (Key point: Preemptive priority trace)

2. Under SRTF at t=5, why does P2 continue instead of P4?
   A. P2 has a higher priority
   B. P2's remaining time 4 is less than P4's burst 6
   C. P2 arrived earlier so it cannot be preempted
   D. P4 has a larger arrival time
   Answer: B. SRTF compares remaining times: P2 has 4 left versus 6 for P4, so P2 continues until 9. (Key point: SRTF decision at t=5)

3. What are AWT and ATAT for preemptive priority?
   A. 9.25 and 17
   B. 9.75 and 17.5
   C. 13 and 23
   D. 6 and 13
   Answer: B. Waiting times 13, 6, 20, 0 sum to 39 (9.75); turnaround 23, 13, 28, 6 sum to 70 (17.5). (Key point: Preemptive priority averages)

4. What are AWT and ATAT for SRTF?
   A. 9.75 and 17.5
   B. 9.25 and 17
   C. 9.25 and 17.5
   D. 10 and 17
   Answer: B. Waiting 13, 0, 20, 4 sum to 37 (9.25); turnaround 23, 7, 28, 10 sum to 68 (17). (Key point: SRTF averages)

## Related in Operating System

- [FCFS, SJF, Priority, RR Gantt; max AWT](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Ascheduling-gantt-fcfs-sjf-priority-rr-q2) — Operating System, chapter 2
- [RR, preemptive priority, preemptive SJF](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aprocess-rr-priority-preemptive-sjf) — Operating System, chapter 2
- [CPU criteria; RR Gantt and times](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acpu-criteria-rr-gantt) — Operating System, chapter 2
- [Real-time scheduling; two-processor numerical](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Arealtime-two-processor-fcfs-sjf-priority-rr) — Operating System, chapter 2
- [Context switching, 5-state model, MLFQ](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Acontext-switch-5state-mlfq) — Operating System, chapter 2
- [FCFS, SJF, RR Gantt and turnaround](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Afcfs-sjf-rr-q5-timeline) — Operating System, chapter 2

## Related in other subjects

- [Preemptive priority scheduling with P4 (6 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-10-5-7-p4) — Embedded System, chapter 6, asked 2×
- [Non-preemptive priority scheduling (10, 5, 7 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-nonpreemptive-10-5-7) — Embedded System, chapter 6, asked 2×
- [Preemptive priority scheduling (4, 10, 5 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-4-10-5-p4) — Embedded System, chapter 6, asked 2×
- [Priority and SJF scheduling with P4 and P5](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-and-sjf-5-process) — Embedded System, chapter 6, asked 2×
