Skip to article
ContentsSJF
Learn/Chapter 02 of 08

SJF Scheduling: Shortest Job First

Shortest Job First (SJF), also called Shortest Process Next, chooses the smallest CPU burst among processes that are ready when the CPU becomes free. After a process starts, this nonpreemptive policy lets it finish.

The rule

The word ready is essential. A scheduler cannot choose a process that has not arrived yet. A shorter arrival also cannot take the CPU away from a process already running under SJF.

Worked example

Example inputs
ProcessArrivalBurst
P107
P213
P321
Scroll horizontally for all columns

One CPU · One burst per process · No I/O · Dispatch cost 0. Times are abstract units.

P1 runs from 0 to 7. Jobs that arrive during its execution cannot interrupt it.

At 7, P3 has burst 1 versus 3 for P2. The shorter ready job wins. The full CPU trace is P1 [0, 7), P3 [7, 8), P2 [8, 11).

Worked trace SJF / SPN
Eligible choices at t = 7
CandidateBurstDecision
P31Selected after P1 completes
P23Waits for P3
Scroll horizontally for all columns
CPU execution: SJFP1 runs [0, 7); P3 runs [7, 8); P2 runs [8, 11). Segment widths show elapsed time. Diamond markers show arrivals. ARRIVALSP1P2P3P1P3P207811Time → Intervals are half-open [start, end). No dispatch overhead.CPU execution: SJFA compact proportional timeline. Diamond markers show arrivals; the complete exact interval sequence follows in text.ARRIVALSP1P2P3P1P3P207811Time →
Scroll horizontally for all intervals
Complete CPU trace · [start, end)
  1. P1: [0, 7)
  2. P3: [7, 8)
  3. P2: [8, 11)
SJF compares eligible bursts only when the CPU becomes free.
Open this example in the simulator

Calculate the result

Per-process results
ProcessCompletionWaitingTurnaroundResponse
P17070
P2117107
P38565
Scroll horizontally for all columns

P3: turnaround = 8 − 2 = 6. Waiting = 6 − 1 = 5. First response = 7 − 2 = 5.

P3 waits 3 units less than with FCFS. P2 waits 1 unit longer. A better average need not help every process.

Mean waiting = (0 + 7 + 5) / 3 = 4 units. Mean response = 4 units.

What SJF assumes

Choosing the shortest burst requires knowing or estimating its length. The simulator uses the burst values you enter. With a continuing supply of short work, a long ready job may be delayed.

Do not apply the phrase "shortest job first" to the entire input table as if every process were available at time 0. Also distinguish SJF from SRTF: SRTF can interrupt current execution, while this SJF policy cannot.