Batch processing represents the foundational operational paradigm of mainframe computing and modern High-Performance Computing (HPC) clusters. In a batch environment, jobs are submitted non-interactively to a spooling queue. Because no human user sits at a terminal waiting for immediate keystroke feedback, the primary optimization objectives shift decisively:
The simplest and most intuitive scheduling discipline is First-Come, First-Served (FCFS). Tasks are assigned the processor strictly in the chronological order of their arrival in the Ready queue.
The operating system manages the Ready list as a standard FIFO (First-In, First-Out) queue. When a job enters the Ready state, its Process Control Block (PCB) is linked to the tail of the queue. The dispatcher repeatedly pulls the task from the queue head, loads its register state, and allows it to run.
Non-Preemptive Invariant: FCFS is strictly non-preemptive. Once a process acquires a CPU core, it retains exclusive ownership until it voluntarily relinquishes control—either by terminating (exit()) or blocking on an I/O request (read(), write()).
Despite its simplicity, FCFS suffers from a severe performance vulnerability known as the convoy effect.
Consider a workload containing one massive, compute-bound process (Process A requiring 24 ms of continuous CPU execution) followed by three lightweight, I/O-bound processes (Processes B, C, and D, each requiring only 3 ms of computation before issuing disk writes).
| Process | Arrival Time | Burst Time | Completion Time | Turnaround Time (Tturnaround) | Waiting Time (Twait) |
|---|---|---|---|---|---|
| Process A | 0 ms | 24 ms | 24 ms | 24 − 0 = 24 ms | 24 − 24 = 0 ms |
| Process B | 0 ms | 3 ms | 27 ms | 27 − 0 = 27 ms | 27 − 3 = 24 ms |
| Process C | 0 ms | 3 ms | 30 ms | 30 − 0 = 30 ms | 30 − 3 = 27 ms |
| Process D | 0 ms | 3 ms | 33 ms | 33 − 0 = 33 ms | 33 − 3 = 30 ms |
To eliminate the convoy effect and minimize average waiting time, batch architectures turn to Shortest Job First (SJF). When the CPU becomes free, the scheduler inspects the Ready queue and selects the job with the smallest required CPU burst duration.
Theorem: When all jobs arrive simultaneously at time T = 0, non-preemptive Shortest Job First is provably optimal: it yields the minimum possible average waiting time and minimum average turnaround time among all non-preemptive algorithms.
Twait(πk) = ∑j=1k−1 tπj
Summing the waiting times across all n jobs yields the total system waiting time:
Total Twait = (n − 1)tπ1 + (n − 2)tπ2 + (n − 3)tπ3 + ... + 1·tπn−1 + 0·tπn
Notice that the burst time of the first job (tπ1) is added into the waiting time of all (n − 1) remaining jobs. The burst time of the second job is added into (n − 2) jobs, and so on.
tπ1 ≤ tπ2 ≤ tπ3 ≤ ... ≤ tπn
Since Average Turnaround Time is simply Average Waiting Time plus the constant mean burst time, minimizing total waiting time simultaneously minimizes average turnaround time. Q.E.D.
Applying non-preemptive SJF to the earlier workload (Jobs B, C, D requiring 3 ms; Job A requiring 24 ms, all available at T = 0):
SJF's mathematical optimality holds strictly only when all candidate jobs arrive simultaneously.
To prevent short jobs from being trapped when they arrive immediately after a long job begins running, operating systems introduce preemption. Shortest Remaining Time Next (SRTN) is the preemptive variant of Shortest Job First.
Whenever a new process enters the Ready queue, the scheduler does not wait for the currently executing process to finish. Instead, it compares the expected remaining execution time of the currently running task against the full burst duration of the newly arrived task:
TASK_RUNNING (in the Ready list), and the dispatcher switches the CPU core to the new task.Process A enters the CPU core at T=0. Because no other jobs exist, Process A is granted immediate execution.
The operating system maximizes hardware utilization by never letting an execution core sit idle when runnable work is present.
The fatal practical limitation of both SJF and SRTN in general-purpose operating systems is obvious: the scheduler cannot know how long a process will execute before it runs. A process may loop three times, read a file, or loop ten million times depending on user input.
To approximate SJF/SRTN, the operating system estimates the next CPU burst duration based on the process's past measured behavior using an exponential moving average (exponential smoothing).
Let tn be the length of the n-th actual, measured CPU burst. Let τn be the predicted value for the n-th burst. The prediction for the upcoming (n + 1)-th burst is calculated recursively as:
τn+1 = αtn + (1 − α)τn
where α (0 ≤ α ≤ 1) is a configurable smoothing parameter that controls the weighting:
Expanding the formula reveals how historical burst observations decay geometrically over time:
τn+1 = αtn + (1 − α)αtn−1 + (1 − α)2αtn−2 + ... + (1 − α)jαtn−j + ... + (1 − α)n+1τ0
Because (1 − α) < 1, the term (1 − α)j shrinks exponentially as j increases. Older burst lengths rapidly lose their mathematical weight. If a process historically performed long 100 ms calculations but recently transitions into an interactive I/O phase (producing 2 ms bursts), τ adjusts downward within 3 to 4 scheduling cycles, dynamically reclassifying the task as short.
Selecting or designing a batch scheduling discipline requires evaluating trade-offs across four foundational axes: average turnaround latency, algorithmic complexity, runtime estimation feasibility, and starvation resistance.
Non-preemptive Shortest Job First (SJF) minimizes average turnaround time, but leaves long compute jobs vulnerable to indefinite starvation if short jobs arrive continuously. Preemptive Shortest Remaining Time Next (SRTN) eliminates this arrival vulnerability, but requires hardware timer preemption and incurs continuous context-switching overhead.
To resolve the starvation dilemma in strictly non-preemptive batch architectures without timer interrupts, Brinch Hansen developed Highest Response Ratio Next (HRRN).
R = (w + s) / s = 1 + (w / s)
where:
w = Time spent waiting in the Ready queue so far.s = Expected CPU service / burst time (estimated via τ).w = 0), its ratio is R = 1.0. As soon as it waits, a small expected burst s in the denominator causes w / s to grow rapidly, giving short jobs quick escalation.s starts with a sluggish ratio. However, as it sits in the queue, its waiting time w accumulates monotonically in the numerator. Eventually, w becomes large enough that the long job's ratio surpasses newly arrived short jobs, guaranteeing execution without preemption.| Algorithm | Selection Rule | Preemption | Turnaround Profile | Starvation Risk | Data Structure & Cost |
|---|---|---|---|---|---|
| FCFS | MIN(Arrival) |
Non-Preemptive | Poor (Degraded by Convoy Effect) | Zero (Monotonic arrival order) | FIFO Queue: O(1) enqueue & dequeue. |
| SJF | MIN(Burst τ) |
Non-Preemptive | Optimal for simultaneous arrivals | High (Continuous short jobs starve long jobs) | Min-Heap: O(log n) insert/extract. |
| SRTN | MIN(Remaining τ) |
Preemptive | Optimal across dynamic arrivals | High (Long tasks can be repeatedly interrupted) | Min-Heap: O(log n) + context switch cost. |
| HRRN | MAX((w+s)/s) |
Non-Preemptive | Near-Optimal (Balances short/long) | Zero (Waiting time w guarantees aging) | Linear scan: O(n) per dispatch. |
ρshort = λshort × E[Sshort] ≥ 1.0
When the utilization generated solely by short tasks equals or exceeds 100% of CPU capacity, the ready queue never clears of short tasks, driving the waiting time of the long job to infinity:
Twait(Long Job) → ∞
In modern High-Performance Computing (HPC) clusters and supercomputer workload managers (such as SLURM, PBS Pro, or HTCondor), CPU cores are scheduled across thousands of nodes executing multi-day scientific simulations.
Because general-purpose exponential smoothing (τ) cannot reliably predict whether a climate model will run for 10 minutes or 48 hours, production HPC systems bypass estimation entirely:
#SBATCH --time=04:00:00). If the job exceeds this duration, the kernel immediately terminates it via SIGKILL.