Example of Non-Preemptive SJF
Given Processes:
| Process | Arrival Time | Burst Time |
|---|---|---|
| P1 | 0 | 7 |
| P2 | 2 | 4 |
| P3 | 4 | 1 |
| P4 | 5 | 4 |
Step 1: Order of Execution
- At time
t=0, only P1 is available, so it starts execution. - At time
t=2, P2 arrives, but P1 continues execution because this is non-preemptive SJF. - At time
t=4, P3 arrives, and after P1 completes, P3 (shortest burst time) is executed. - At time
t=5, P4 arrives, and P2 is scheduled next after P3.
Gantt Chart:
| Time | 0 – 7 | 7 – 8 | 8 – 12 | 12 – 16 |
|---|---|---|---|---|
| P | P1 | P3 | P2 | P4 |
Step 2: Calculations
Turnaround Time (TAT) = Completion Time – Arrival Time
Waiting Time (WT) = Turnaround Time – Burst Time
| Process | Arrival Time | Burst Time | Completion Time | TAT | WT |
|---|---|---|---|---|---|
| P1 | 0 | 7 | 7 | 7 | 0 |
| P2 | 2 | 4 | 12 | 10 | 6 |
| P3 | 4 | 1 | 8 | 4 | 3 |
| P4 | 5 | 4 | 16 | 11 | 7 |
Step 3: Averages
- Average Turnaround Time (TAT) = 7+10+4+114=8\frac{7 + 10 + 4 + 11}{4} = 847+10+4+11=8
- Average Waiting Time (WT) = 0+6+3+74=4\frac{0 + 6 + 3 + 7}{4} = 440+6+3+7=4
Advantages of SJF
- Minimizes average waiting time.
- Optimal for systems where short tasks dominate.
Disadvantages of SJF
- Difficult to predict the exact burst time of a process.
- Starvation of longer processes if shorter ones keep arriving.
Example -2:Below is the full solution for SJF (Shortest Job First) Non-Preemptive scheduling for the given processes.
Given Processes
| Process | Arrival Time | Burst Time |
|---|---|---|
| P1 | 0 | 5 |
| P2 | 2 | 3 |
| P3 | 3 | 2 |
| P4 | 1 | 3 |
SJF (Non-Preemptive) Scheduling
Step 1: Sort by arrival, choose shortest burst among available processes
Timeline Execution
At time = 0
Available: P1
→ Run P1 (burst 5) until completion (non-preemptive)
P1 runs from 0 → 5
At time = 5
Now available: P2 (3), P3 (2), P4 (3)
Shortest = P3
P3 runs from 5 → 7
At time = 7
Remaining: P2 (3), P4 (3)
Tie → choose the one that arrived first → P4
P4 runs from 7 → 10
At time = 10
Last: P2 (3)
P2 runs from 10 → 13
Gantt Chart
| P1 | P3 | P4 | P2 |
0 5 7 10 13
Completion, Turnaround, and Waiting Times
| Process | AT | BT | CT | TAT = CT-AT | WT = TAT-BT |
|---|---|---|---|---|---|
| P1 | 0 | 5 | 5 | 5 | 0 |
| P3 | 3 | 2 | 7 | 4 | 2 |
| P4 | 1 | 3 | 10 | 9 | 6 |
| P2 | 2 | 3 | 13 | 11 | 8 |
Average Times
Average Turnaround Time
5+4+9+11/=4 29/4
=7.25 ms
Average Waiting Time
0+2+6+8/4=16/4= 4 ms
✅ Final Answer Summary
Gantt Chart:
0–5(P1), 5–7(P3), 7–10(P4), 10–13(P2)