CPU Scheduling Case Study: FCFS vs SJF for a Five-Process Workload

CPU Scheduling Case Study: FCFS vs SJF for a Five-Process Workload

Verified Sources
May 27, 2026

This section analyzes two classic CPU scheduling algorithms—FCFS and SJF—for the following workload, where all processes arrive at time 00 in the order A,B,C,D,EA, B, C, D, E.2

ProcessBurst Time (ms)Priority
A103
B11
C23
D14
E52

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:

Waiting Time=Start TimeArrival Time\text{Waiting Time} = \text{Start Time} - \text{Arrival Time}

Since every arrival time is 00, each process's waiting time is simply its start time.2

A second equivalent relation often used in operating systems is:

Waiting Time=Turnaround TimeBurst Time\text{Waiting Time} = \text{Turnaround Time} - \text{Burst Time}

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

  1. Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. 2 3

  2. Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. 2 3 4

  3. 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 00, preemptive and non-preemptive behavior would not differ before the first dispatch unless new arrivals occurred later.2

Footnotes

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

1. FCFS Scheduling

Under FCFS, processes execute strictly in arrival order: ABCDEA \rightarrow B \rightarrow C \rightarrow D \rightarrow E. Since all processes arrive at the same instant, the given arrival order breaks the tie.

The Gantt chart is:

Time01011131419
ProcessABCDE

Equivalently, the execution intervals are:

  • A:010A: 0 \to 10
  • B:1011B: 10 \to 11
  • C:1113C: 11 \to 13
  • D:1314D: 13 \to 14
  • E:1419E: 14 \to 19

For FCFS, the waiting times are the start times:

ProcessStart TimeWaiting Time
A00
B1010
C1111
D1313
E1414

Thus,

Average Waiting TimeFCFS=0+10+11+13+145=485=9.6 ms\text{Average Waiting Time}_{FCFS} = \frac{0+10+11+13+14}{5} = \frac{48}{5} = 9.6 \text{ ms}

This illustrates the classic FCFS weakness: short jobs may wait behind a long job, increasing the mean waiting time.2

Footnotes

  1. CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF. 2

  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

  1. 1
    Step 1

    Because every process arrives at time 00, the given order A,B,C,D,EA, B, C, D, E is used directly.

    Footnotes

    1. CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF.

  2. 2
    Step 2

    Process AA runs from time 00 to time 1010 because its burst time is 1010 ms.

  3. 3
    Step 3

    After AA finishes, BB runs from time 1010 to time 1111.

  4. 4
    Step 4

    Next, CC runs from time 1111 to time 1313.

  5. 5
    Step 5

    Then, DD runs from time 1313 to time 1414.

  6. 6
    Step 6

    Finally, EE runs from time 1414 to time 1919.

  7. 7
    Step 7

    Since arrival time is 00 for every process, each waiting time equals the point where that process begins execution.

    Footnotes

    1. 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 00, we sort by burst length:

  • B=1B = 1
  • D=1D = 1
  • C=2C = 2
  • E=5E = 5
  • A=10A = 10

When two processes have equal burst times, a common tie-break rule is FCFS among tied processes.2 Since BB arrived before DD, the SJF order is:

BDCEAB \rightarrow D \rightarrow C \rightarrow E \rightarrow A

The Gantt chart is:

Time0124919
ProcessBDCEA

Execution intervals:

  • B:01B: 0 \to 1
  • D:12D: 1 \to 2
  • C:24C: 2 \to 4
  • E:49E: 4 \to 9
  • A:919A: 9 \to 19

Waiting times:

ProcessStart TimeWaiting Time
B00
D11
C22
E44
A99

So,

Average Waiting TimeSJF=0+1+2+4+95=165=3.2 ms\text{Average Waiting Time}_{SJF} = \frac{0+1+2+4+9}{5} = \frac{16}{5} = 3.2 \text{ ms}

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

  1. Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time. 2

  2. Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples. 2 3

  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

  1. 1
    Step 1

    At time 00, every process is already in the ready queue, so the scheduler can compare all burst times immediately.

    Footnotes

    1. Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time.

  2. 2
    Step 2

    Order the processes by ascending CPU burst: 1,1,2,5,101, 1, 2, 5, 10.

  3. 3
    Step 3

    Processes BB and DD both have burst time 11, so BB goes first because it arrived earlier in the given order.

    Footnotes

    1. Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples.

  4. 4
    Step 4

    Mark B:01B: 0\to1, D:12D: 1\to2, C:24C: 2\to4, E:49E: 4\to9, and A:919A: 9\to19.

  5. 5
    Step 5

    Use each start time as the waiting time because all arrival times are 00.

  6. 6
    Step 6

    Add the waiting times and divide by 55 to obtain 3.23.2 ms.

Average Waiting Time Comparison

Lower values indicate better average queueing performance for this workload.2

Footnotes

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

Fast Exam Shortcut

If all arrival times are 00, 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

  1. Shortest Job First or SJF CPU Scheduling - GeeksforGeeks - Overview of non-preemptive SJF, waiting-time formulas, and worked Gantt-chart examples.

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

  1. Operating Systems: CPU Scheduling - Course notes explaining FCFS, SJF, Gantt charts, and the optimality of SJF for minimizing average waiting time.

  2. CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF.

OrderABCDE
Burst101215
Start010111314
Wait010111314

Average waiting time =9.6= 9.6 ms.

Chronological Execution Comparison

Start with A

FCFS

The long 1010 ms job AA runs first because it arrived first, causing all shorter jobs to wait."

Footnotes

  1. CPU Scheduling in Operating Systems - GeeksforGeeks - Definitions of burst time, turnaround time, waiting time, and a comparison of FCFS and SJF.

Short jobs delayed

FCFS

Processes BB, CC, and DD incur waiting times of 1010, 1111, and 1313 ms respectively."

Shortest jobs first

SJF

Processes with burst times 1,1,21, 1, 2 run before the longer jobs, reducing queue delay.2"

Footnotes

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

Lower average wait

SJF

The computed average waiting time drops from 9.69.6 ms to 3.23.2 ms."

Worked Clarifications and Edge Cases

Final Answer

The required Gantt charts are:

FCFS

01011131419
ABCDE

SJF

0124919
BDCEA

Average waiting times:

FCFS=9.6 ms\text{FCFS} = 9.6 \text{ ms} SJF=3.2 ms\text{SJF} = 3.2 \text{ ms}

Therefore, SJF results in the minimum average waiting time.2

Footnotes

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

Knowledge Check

Question 1 of 5
Q1Single choice

What is the FCFS execution order for the given processes when all arrive at time 00?

Explore Related Topics

1

Writing a C Program with `fork()` to Demonstrate the Parent-Child Relationship of Processes

The article shows how to write a C program that uses fork() to illustrate the parent‑child relationship of processes, their return values, IDs, concurrent execution, and proper synchronization.

  • fork() returns 0 in the child, the child’s PID in the parent, and -1 on error.
  • getpid() and getppid() reveal each process’s own and parent IDs; output order can vary because the two processes run concurrently.
  • The parent must call waitpid() (or wait()) to reap the child, prevent zombies, and decode its exit status with WIFEXITED/WEXITSTATUS.
  • Changing a variable (e.g., x) in the child demonstrates separate writable address spaces, thanks to copy‑on‑write.
  • Avoid placing fork() in an uncontrolled loop, as each successful fork doubles the process count from 11 to 22, then to 2n2^n, quickly exhausting system resources.
2

Complexity Analysis: Best Case, Worst Case, and Average Case

The material introduces best‑case, worst‑case, and average‑case complexity as three distinct functions describing an algorithm’s running time on inputs of size nn, explains how they are formally defined, and shows why worst‑case analysis is usually preferred.

  • Best case: Tbest(n)=minIInT(I)T_{\text{best}}(n)=\min_{I\in\mathcal I_n} T(I), the minimum time over all inputs of size nn.
  • Worst case: Tworst(n)=maxIInT(I)T_{\text{worst}}(n)=\max_{I\in\mathcal I_n} T(I), giving a guaranteed upper bound.
  • Average case: Tavg(n)=IInP(I)T(I)T_{\text{avg}}(n)=\sum_{I\in\mathcal I_n}P(I)\,T(I), requiring an explicit input probability model.
  • Linear search illustrates the three cases: Θ(1)\Theta(1) best, Θ(n)\Theta(n) worst, and Θ(n)\Theta(n) average (expected n+12\frac{n+1}{2} comparisons).
  • Worst‑case analysis is favored because it needs no probabilistic assumptions and ensures reliability for all inputs, especially in real‑time or safety‑critical systems.
3

Banker's Algorithm Safe-State Analysis for Processes $P_0$ Through $P_4$

The course walks through a full Banker's‑algorithm safety analysis for processes P0P_0P4P_4, computing the Need matrix and using the work‑vector test to verify a safe state and a valid completion order.

  • Need matrix: P0  (0,0,0,0)P_0\;(0,0,0,0), P1  (0,7,5,0)P_1\;(0,7,5,0), P2  (1,0,0,2)P_2\;(1,0,0,2), P3  (0,0,2,0)P_3\;(0,0,2,0), P4  (0,6,4,2)P_4\;(0,6,4,2).
  • Starting work Work=Available=(1,5,2,0)Work = Available = (1,5,2,0); each step selects a process with NeedWorkNeed \le Work, releases its allocation, and updates WorkWork.
  • All processes finish, yielding a safe sequence P0,P2,P1,P3,P4\langle P_0, P_2, P_1, P_3, P_4\rangle.
  • A safe state requires only one such sequence; it does not mean every immediate allocation is safe.
  • Exam tip: test processes with minimal or zero Need first to unlock the rest.