Best on a larger screen — the animation and controls have more room to breathe.
Inputs

Process Scheduling

Process scheduling handles a basic operating-system constraint: one CPU must be shared among many runnable processes. At each decision point, the scheduler selects which ready process runs next. This lesson runs a fixed four-process workload under three classic policies (FCFS, SJF, and Round Robin) so you can compare their Gantt charts directly.

Think of a single grocery cashier serving four customers who arrive over four minutes with different cart sizes: the store can serve in arrival order, let smaller baskets go first, or scan two items per customer and rotate everyone to the back of the line. The cashier corresponds to the CPU, and the line rule corresponds to the scheduling policy.

How Process Scheduling Works

Three elements represent the system state. The ready queue holds processes that have arrived and are waiting for the CPU. The CPU executes one process at a time. The Gantt chart records a timeline showing which process held the CPU during each interval.

Each policy defines one decision, the dispatch: which process moves from the ready queue to the CPU.

FCFS (First-Come, First-Served) dispatches the process at the front of the queue in arrival order and runs it to completion without interruption.

SJF (Shortest Job First) dispatches the ready process with the smallest burst and runs it to completion. This is the non-preemptive variant: a job already on the CPU finishes its burst even if a shorter job arrives mid-run. Ties on burst go to the earlier arrival.

Round Robin dispatches from the front of the queue but limits each turn to one quantum (2 time units by default; the slider ranges from 1 to 4). A process that finishes within its slice completes; otherwise it is preempted, moved to the back of the ready queue, and the next queued process runs. Any process arriving during the slice joins the queue before the preempted process re-enters.

Two metrics measure each process. Turnaround time is completion time minus arrival time (total time in the system). Waiting time is turnaround time minus CPU burst (total time spent in the ready queue). Averaging both metrics across all four processes summarizes the policy's performance.

The fixed workload has four processes: P1 arrives at t = 0 with burst 5, P2 at t = 1 with burst 3, P3 at t = 2 with burst 1, and P4 at t = 3 with burst 2. Placing one long job ahead of three shorter arrivals makes the differences between the three policies visible.

Process Scheduling Step by Step

The default policy is FCFS, which executes processes strictly in arrival order.

At t = 0, only P1 has arrived, so it runs its full burst of 5 across [0, 5]. While P1 executes, P2 arrives at t = 1, P3 at t = 2, and P4 at t = 3, waiting in the ready queue. P1 completes at t = 5 with turnaround 5 − 0 = 5 and wait 5 − 5 = 0.

P2 runs next across [5, 8] and completes at t = 8 (turnaround 8 − 1 = 7, wait 7 − 3 = 4). P3 runs across [8, 9]; despite needing only one unit of CPU, it finishes at t = 9 with turnaround 7 and wait 6. P4 runs across [9, 11] and finishes at t = 11 with turnaround 8 and wait 6.

Final FCFS Gantt: P1[0,5] P2[5,8] P3[8,9] P4[9,11]. Average waiting time is (0 + 4 + 6 + 6) / 4 = 4.00, and average turnaround is (5 + 7 + 7 + 8) / 4 = 6.75. P3 needs one unit of CPU time but waits six units behind longer jobs. Shorter jobs stuck behind one long CPU burst is the convoy effect, a standard failure mode of FCFS.

Switching the selector to SJF reorders the schedule after P1 finishes. At t = 5, the ready queue holds P2 (burst 3), P3 (burst 1), and P4 (burst 2), so the scheduler picks the shortest burst first, giving P1[0,5] P3[5,6] P4[6,8] P2[8,11]. P3 waits 3, P4 waits 3, and P2 (the longest of the three waiting jobs) waits 7. Average waiting time drops to 3.25, and average turnaround drops to 6.00.

Switching to Round Robin with quantum 2 splits execution into seven slices: P1[0,2] P2[2,4] P3[4,5] P1[5,7] P4[7,9] P2[9,10] P1[10,11]. At t = 2, P3 arrives at the same instant P1's quantum expires, and P3 enters the queue before the preempted P1 re-joins. P3 completes at t = 5 (wait 2), P4 at t = 9 (wait 4), P2 at t = 10 (wait 6), and P1 finishes across three slices at t = 11 (wait 6). Average waiting time rises to 4.50 and average turnaround rises to 7.25, while every process receives its first CPU slice within the first 7 time units.

On the canvas, each process keeps one color across the ready queue, CPU box, and Gantt chart so you can track an individual job over time. Per-process wait counters increment while a job sits in the queue; under FCFS, P3's wait counter climbs while P1 runs. Under Round Robin, the CPU box displays a quantum meter tracking time used in the current slice, triggering preemption when it fills and the job still has remaining work.

Which Scheduling Policy Wins?

Each policy optimizes a different metric. On this workload, FCFS averages 4.00 wait and 6.75 turnaround, SJF averages 3.25 wait and 6.00 turnaround, and Round Robin averages 4.50 wait and 7.25 turnaround.

SJF produces the lowest averages here. When all jobs are ready simultaneously and their burst lengths are known, non-preemptive shortest-first order minimizes average waiting time (with staggered arrivals, greedy non-preemptive SJF is not always globally optimal). In practice, however, operating systems cannot know exact future burst lengths and must estimate them, and a steady stream of short jobs can starve a long job indefinitely.

Round Robin produces the highest average wait and turnaround on this workload, yet it is closest to what general-purpose operating systems use. It guarantees bounded response delay and prevents starvation without needing burst estimates, a tradeoff interactive systems accept despite higher average waiting time. FCFS is simple to implement and preserves arrival order, but a single long CPU burst causes a convoy behind it.

Edge Cases

  • Idle CPU. If the ready queue is empty while future processes have not arrived yet, the clock advances to the next arrival and the Gantt chart draws a hatched idle gap. The default workload never goes idle.
  • Completion at a quantum boundary. A Round Robin process whose remaining burst equals the quantum completes at the end of that slice rather than being preempted and re-queued with zero work left.
  • Arrival at the instant of preemption. When a new arrival coincides with quantum expiry (such as P3 at t = 2), the newly arrived process enters the ready queue ahead of the preempted process. Textbook conventions vary; this is the order the animation simulates.
  • SJF ties. Processes with equal bursts are dispatched in arrival order.

Common Mistakes

  • Confusing waiting time with turnaround time. Turnaround time includes CPU execution time, while waiting time excludes it. For P3 under FCFS, turnaround is 7 and wait is 6; the difference of 1 is its burst length.
  • Treating SJF as universally best. SJF lowers average wait here and is optimal when all jobs are available at once, but it requires knowing burst lengths in advance and can starve long jobs.
  • Assuming a smaller quantum is always better. Smaller quanta improve response time but increase the number of context switches. This model charges zero cost per switch, whereas real hardware incurs real overhead; setting quantum to 1 shows how quickly the slice count grows.

A Note on Simplification

This model simulates a single CPU running CPU-bound jobs with zero-cost context switches and known burst lengths so the scheduling decision stays isolated. Production operating systems pay real overhead on every context switch, cannot see future burst lengths in advance, and combine multi-level feedback queues, priorities with aging, and per-core load balancing on top of these core policies.