---
title: "Preemptive priority scheduling with P4 (6 ms)"
subject: "Embedded System"
chapter: 6
key: "semester_6/embedded_system:sched-priority-10-5-7-p4"
source: https://www.bctengineer.com/q/semester_6/embedded_system/sched-priority-10-5-7-p4
site: BCT Engineering
---

# Preemptive priority scheduling with P4 (6 ms)

Embedded System · Chapter 6: RTOS

- Asked in: 2071 Magh, 8 marks; 2073 Bhadra, 5 marks (asked 2 times)
- Video: [L-2.8: Pre-emptive Priority  Scheduling Algorithm with  Example | Operating System](https://www.youtube.com/watch?v=rsDGfFxSgiY) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/embedded_system/sched-priority-10-5-7-p4
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-6

## Question

In priority based (preemptive) scheduling, three processes IDs P1, P2, P3 with estimated completion time 10, 5, 7 msec. and priorities 1, 3, 2 (0-highest and 3-lowest priority) respectively enter the ready queue together. A new process P4 with estimated completion time 6 ms and priority 0 enters the ready queue after 5 ms of start of execution of P1. Calculate the waiting time and turn around time for each process and the average waiting time and average TAT. Assume all the processes contain only CPU operation and no I/O operations are involved.

## Short answer

Preemptive priority (0 highest). Schedule: P1(0-5), P4(5-11), P1(11-16), P3(16-23), P2(23-28). Waiting times: P1=6ms, P2=23ms, P3=16ms, P4=0ms; average=11.25ms. Turnaround times: P1=16ms, P2=28ms, P3=23ms, P4=6ms; average=18.25ms.

## Answer

**Preemptive priority scheduling** (0 = highest priority): the CPU always runs the highest-priority ready process; a newly arrived higher-priority process pre-empts the running one. WT = TAT - burst; TAT = completion - arrival.

| Process | Arrival | Burst | Priority |
|---|---|---|---|
| P1 | 0 | 10 | 1 |
| P2 | 0 | 5 | 3 |
| P3 | 0 | 7 | 2 |
| P4 | 5 | 6 | 0 |

#### Schedule
- 0 to 5: P1 (priority 1, best of P1/P2/P3) runs; 5 ms remain.
- t = 5: P4 (priority 0) arrives and pre-empts P1. P4 runs 5 to 11.
- 11 to 16: P1 resumes, finishes its remaining 5 ms (priority 1).
- 16 to 23: P3 (priority 2) runs 7 ms.
- 23 to 28: P2 (priority 3) runs 5 ms.

```text
 |   P1   |    P4    |   P1   |     P3     |   P2   |
 0        5          11       16           23       28
```

| Process | Completion | TAT | WT |
|---|---|---|---|
| P1 | 16 | 16 - 0 = 16 | 16 - 10 = 6 |
| P2 | 28 | 28 - 0 = 28 | 28 - 5 = 23 |
| P3 | 23 | 23 - 0 = 23 | 23 - 7 = 16 |
| P4 | 11 | 11 - 5 = 6 | 6 - 6 = 0 |

Average WT = (6 + 23 + 16 + 0) / 4 = 45 / 4 = **11.25 ms**
Average TAT = (16 + 28 + 23 + 6) / 4 = 73 / 4 = **18.25 ms**

## Check yourself

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

1. In preemptive priority scheduling (0 = highest), what happens when P4 (priority 0) arrives at t = 5 while P1 (priority 1) is running?
   A. P1 continues to finish and P4 waits
   B. P1 is pre-empted with 5 ms left and P4 runs
   C. P4 waits until all of P2 and P3 finish
   D. P1 and P4 share the CPU in time slices
   Answer: B. A newly arrived higher-priority process pre-empts the running one, so P4 runs from 5 to 11 and P1 has 5 ms remaining. (Key point: Preemption at arrival)

2. Which is the correct order of execution in the Gantt chart?
   A. P1, P4, P1, P3, P2
   B. P1, P4, P1, P2, P3
   C. P1, P2, P3, P4
   D. P1, P3, P2, P4
   Answer: A. After P4, P1 (priority 1) resumes, then P3 (priority 2), then P2 (priority 3). (Key point: Order of execution)

3. How are TAT and WT computed for P4, which arrives at 5 and completes at 11 with burst 6?
   A. TAT = 11, WT = 5
   B. TAT = 11 - 5 = 6, WT = 6 + 6 = 12
   C. TAT = 11, WT = 11 - 6 = 5
   D. TAT = 11 - 5 = 6, WT = 6 - 6 = 0
   Answer: D. TAT = completion - arrival and WT = TAT - burst; arrival time must be subtracted. (Key point: WT and TAT formulas)

4. What are the average waiting time and average TAT?
   A. 10.25 ms and 17.25 ms
   B. 11.25 ms and 16 ms
   C. 11.25 ms and 18.25 ms
   D. 18.25 ms and 11.25 ms
   Answer: C. WT = 6, 23, 16, 0 gives 45/4 = 11.25; TAT = 16, 28, 23, 6 gives 73/4 = 18.25. (Key point: Final averages)

## Related in Embedded System

- [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×
- [Priority scheduling (7, 8, 5 ms) with P4](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-7-8-5-p4) — 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×
- [Preemptive priority scheduling (4, 6, 5 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-4-6-5) — Embedded System, chapter 6
- [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×
- [Preemptive SJF/SRT scheduling (10, 5, 7 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-srt-10-5-7) — Embedded System, chapter 6

## Related in other subjects

- [Preemptive priority and SRTF Gantt](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Apreemptive-priority-srtf-gantt) — 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
