CPU Scheduling Case Study: FCFS vs SJF for a Five-Process Workload
This section analyzes two classic CPU scheduling algorithms—FCFS and SJF—for the following workload, where all processes arrive at time in the order .2
| Process | Burst Time (ms) | Priority |
|---|---|---|
| A | 10 | 3 |
| B | 1 | 1 |
| C | 2 | 3 |
| D | 1 | 4 |
| E | 5 | 2 |
Because all processes arrive simultaneously, waiting time depends entirely on execution order, and average waiting time is a standard metric for comparing scheduling quality. For this problem, the priority column is not used, because the question asks only for FCFS and non-preemptive SJF schedules.2
A useful identity is:
Since every arrival time is , each process's waiting time is simply its start time.2
A second equivalent relation often used in operating systems is:
where turnaround time equals completion time minus arrival time.2
The key theoretical result is that non-preemptive SJF minimizes average waiting time when burst lengths are known in advance for a fixed set of ready processes.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩ ↩2 ↩3
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩ ↩2 ↩3 ↩4
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩ ↩2 ↩3 ↩4
Shortest Job First(SJF) Scheduling Algorithm with example | Operating System
Interpretation Assumption
Because the prompt asks for SJF without mentioning preemption, the standard interpretation is non-preemptive SJF. Since all processes arrive at time , preemptive and non-preemptive behavior would not differ before the first dispatch unless new arrivals occurred later.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
1. FCFS Scheduling
Under FCFS, processes execute strictly in arrival order: . Since all processes arrive at the same instant, the given arrival order breaks the tie.
The Gantt chart is:
| Time | 0 | 10 | 11 | 13 | 14 | 19 |
|---|---|---|---|---|---|---|
| Process | A | B | C | D | E |
Equivalently, the execution intervals are:
For FCFS, the waiting times are the start times:
| Process | Start Time | Waiting Time |
|---|---|---|
| A | 0 | 0 |
| B | 10 | 10 |
| C | 11 | 11 |
| D | 13 | 13 |
| E | 14 | 14 |
Thus,
This illustrates the classic FCFS weakness: short jobs may wait behind a long job, increasing the mean waiting time.2
Footnotes
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩ ↩2
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩ ↩2
How to Build the FCFS Gantt Chart
- 1Step 1
Because every process arrives at time , the given order is used directly.
Footnotes
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩
-
- 2Step 2
Process runs from time to time because its burst time is ms.
- 3Step 3
After finishes, runs from time to time .
- 4Step 4
Next, runs from time to time .
- 5Step 5
Then, runs from time to time .
- 6Step 6
Finally, runs from time to time .
- 7Step 7
Since arrival time is for every process, each waiting time equals the point where that process begins execution.
Footnotes
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
-
2. SJF Scheduling
In non-preemptive SJF, the ready process with the smallest burst time is selected first.2 With all processes available at time , we sort by burst length:
When two processes have equal burst times, a common tie-break rule is FCFS among tied processes.2 Since arrived before , the SJF order is:
The Gantt chart is:
| Time | 0 | 1 | 2 | 4 | 9 | 19 |
|---|---|---|---|---|---|---|
| Process | B | D | C | E | A |
Execution intervals:
Waiting times:
| Process | Start Time | Waiting Time |
|---|---|---|
| B | 0 | 0 |
| D | 1 | 1 |
| C | 2 | 2 |
| E | 4 | 4 |
| A | 9 | 9 |
So,
This is substantially smaller than FCFS, which matches the standard result that SJF is optimal for minimizing average waiting time when burst durations are known.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩ ↩2
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩ ↩2 ↩3
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩
How to Build the SJF Gantt Chart
- 1Step 1
At time , every process is already in the ready queue, so the scheduler can compare all burst times immediately.
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
- 2Step 2
Order the processes by ascending CPU burst: .
- 3Step 3
Processes and both have burst time , so goes first because it arrived earlier in the given order.
Footnotes
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
-
- 4Step 4
Mark , , , , and .
- 5Step 5
Use each start time as the waiting time because all arrival times are .
- 6Step 6
Add the waiting times and divide by to obtain ms.
Average Waiting Time Comparison
Lower values indicate better average queueing performance for this workload.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
Fast Exam Shortcut
If all arrival times are , the waiting time of each process is just the sum of burst times of all processes scheduled before it. This makes Gantt-chart calculations much faster.2
Footnotes
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩
Common Mistake
Do not use the priority column here. Priority scheduling is a different algorithm. For this question, only FCFS and SJF determine execution order.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩
| Order | A | B | C | D | E |
|---|---|---|---|---|---|
| Burst | 10 | 1 | 2 | 1 | 5 |
| Start | 0 | 10 | 11 | 13 | 14 |
| Wait | 0 | 10 | 11 | 13 | 14 |
Average waiting time ms.
Chronological Execution Comparison
Start with A
FCFSThe long ms job runs first because it arrived first, causing all shorter jobs to wait."
Footnotes
-
CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. ↩
Short jobs delayed
FCFSProcesses , , and incur waiting times of , , and ms respectively."
Shortest jobs first
SJFProcesses with burst times run before the longer jobs, reducing queue delay.2"
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
Lower average wait
SJFThe computed average waiting time drops from ms to ms."
Worked Clarifications and Edge Cases
Final Answer
The required Gantt charts are:
FCFS
| 0 | 10 | 11 | 13 | 14 | 19 |
|---|---|---|---|---|---|
| A | B | C | D | E |
SJF
| 0 | 1 | 2 | 4 | 9 | 19 |
|---|---|---|---|---|---|
| B | D | C | E | A |
Average waiting times:
Therefore, SJF results in the minimum average waiting time.2
Footnotes
-
Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. ↩
-
Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. ↩
Knowledge Check
What is the FCFS execution order for the given processes when all arrive at time ?
Explore Related Topics
Systems Programming: Processes, Memory, Concurrency, and Operating-System Interfaces
SSTF Disk Scheduling Worked Example: Total Head Movement for the Given Request Queue
The example applies the Shortest Seek Time First (SSTF) disk‑scheduling algorithm to a pending request queue, starting from head position 143, and computes the total cylinder movement.
- Service order by minimum distance:
- Stepwise moves: cylinders, giving total movement cylinders
- The previous request at only hints at recent direction; SSTF selects the nearest pending request regardless of it
- SSTF typically lowers seek time versus FIFO but can starve distant requests, and a straightforward simulation runs in time.
Memory Allocation with First-Fit and Best-Fit
