---
title: "Non-preemptive SJF with P4 arriving"
subject: "Embedded System"
chapter: 6
key: "semester_6/embedded_system:sched-sjf-nonpreemptive-6-8-2"
source: https://www.bctengineer.com/q/semester_6/embedded_system/sched-sjf-nonpreemptive-6-8-2
site: BCT Engineering
---

# Non-preemptive SJF with P4 arriving

Embedded System · Chapter 6: RTOS

- Asked in: 2070 Bhadra, 3 marks; 2075 Baisakh, 5 marks (asked 2 times)
- Video: [L-2.4: Shortest Job First(SJF) Scheduling  Algorithm with  Example | Operating System](https://www.youtube.com/watch?v=VCIVXPoiLpU) — 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-sjf-nonpreemptive-6-8-2
- Whole chapter: https://www.bctengineer.com/md/semester_6/embedded_system/chapter-6

## Question

Three processes with process IDs P1, P2, P3 with estimated completion times 6, 8, 2 milliseconds respectively enter the ready queue together (in the order P1, P2, P3). Process P4 with estimated execution completion time 4 milliseconds enters the ready queue after 1 millisecond. Calculate the waiting time and turn-around-time (TAT) for each process and the average waiting time and TAT in the non-preemptive shortest-job-first scheduling.

## Short answer

Non-preemptive SJF selects shortest burst when CPU free. Schedule: P3(0-2), P4(2-6), P1(6-12), P2(12-20). Waiting times: P1=6ms, P2=12ms, P3=0ms, P4=1ms; average=4.75ms. Turnaround times: P1=12ms, P2=20ms, P3=2ms, P4=5ms; average=9.75ms.

## Answer

**Non-preemptive SJF:** when the CPU becomes free, the ready process with the shortest burst time is selected, and it runs until it finishes. Waiting time (WT) = start time - arrival time; turnaround time (TAT) = completion time - arrival time = WT + burst time.

| Process | Arrival (ms) | Burst (ms) |
|---|---|---|
| P1 | 0 | 6 |
| P2 | 0 | 8 |
| P3 | 0 | 2 |
| P4 | 1 | 4 |

#### Schedule
- t = 0: P1, P2, P3 are ready, the shortest is P3 (2 ms), so P3 runs from 0 to 2 (it cannot be interrupted when P4 arrives at t = 1).
- t = 2: P1 (6), P2 (8), P4 (4) are ready, the shortest is P4: runs 2 to 6.
- t = 6: P1 (6) then P2 (8): P1 runs 6 to 12.
- t = 12: P2 runs 12 to 20.

```text
 | P3 |   P4   |     P1     |        P2        |
 0    2        6            12                 20
```

| Process | Completion | TAT = CT - AT | WT = TAT - Burst |
|---|---|---|---|
| P1 | 12 | 12 - 0 = 12 | 12 - 6 = 6 |
| P2 | 20 | 20 - 0 = 20 | 20 - 8 = 12 |
| P3 | 2 | 2 - 0 = 2 | 2 - 2 = 0 |
| P4 | 6 | 6 - 1 = 5 | 5 - 4 = 1 |

Average WT = (6 + 12 + 0 + 1) / 4 = 19 / 4 = **4.75 ms**
Average TAT = (12 + 20 + 2 + 5) / 4 = 39 / 4 = **9.75 ms**

## Check yourself

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

1. At t = 1, P4 (4 ms) arrives while P3 (2 ms) is running. What happens?
   A. P1 starts
   B. P2 starts
   C. P3 continues to finish, because non-preemptive
   D. P4 pre-empts P3
   Answer: C. Non-preemptive SJF cannot interrupt a running process. (Key point: Non-preemptive SJF rule)

2. What is the execution order?
   A. P3, P4, P1, P2
   B. P3, P1, P4, P2
   C. P1, P2, P3, P4
   D. P3, P4, P2, P1
   Answer: A. At t=2 shortest is P4 (4), then P1 (6), then P2 (8). (Key point: Order of execution)

3. What is P4's waiting time?
   A. 5 ms
   B. 1 ms
   C. 4 ms
   D. 2 ms
   Answer: B. P4 starts at 2, arrived at 1, so WT = 1 (TAT = 5). (Key point: Waiting time of P4)

4. What is the average WT?
   A. 5 ms
   B. 4 ms
   C. 9.75 ms
   D. 4.75 ms
   Answer: D. WT: P1 6, P2 12, P3 0, P4 1; 19/4 = 4.75 (average TAT 9.75). (Key point: Average waiting time)

## Related in Embedded System

- [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×
- [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
- [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 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×
- [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, 6, 5 ms)](https://www.bctengineer.com/question.md?key=semester_6%2Fembedded_system%3Asched-priority-4-6-5) — Embedded System, chapter 6

## Related in other subjects

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