🖥️ CPU Scheduling — FCFS, SJF, Round Robin
Schedule processes on a CPU with FCFS, SJF, priority and round-robin policies. An animated Gantt chart shows context switches while average waiting and turnaround times update live.
About CPU Scheduling
This simulation models how an operating system shares a single CPU among several competing processes. Each process has an arrival time, a CPU burst length and a priority. The scheduler computes a complete execution timeline one time unit at a time under the chosen policy, then renders it as an animated Gantt chart. From that timeline it derives each process's completion, turnaround and waiting times using the standard relations turnaround = completion − arrival and waiting = turnaround − burst.
The Policy selector switches between FCFS, SJF, SRTF, non-preemptive Priority and Round Robin, and the Quantum slider (1–6) sets the time slice used by Round Robin. The Count slider (2–7) sets how many processes are generated, Randomise rerolls their arrival, burst and priority values, and Speed controls playback while Step advances one unit. CPU scheduling is fundamental to operating systems: the same trade-offs between throughput, fairness and response time govern real schedulers in Linux, Windows and embedded real-time kernels.
Frequently Asked Questions
What does this CPU scheduling simulation actually compute?
It builds a full execution timeline by selecting one process per unit of time according to the chosen policy. From the finish times it works out each process's completion, turnaround (completion minus arrival) and waiting (turnaround minus burst), and counts every context switch where the running process changes.
Which scheduling policies can I choose?
Five policies are available: FCFS (First-Come First-Served), SJF (Shortest Job First, non-preemptive), SRTF (preemptive shortest remaining time), Priority (non-preemptive, lower number means higher priority) and Round Robin. Selecting a policy recomputes the timeline immediately on the same set of processes so you can compare them.
What do the Quantum, Count and Speed controls do?
Quantum (1 to 6) is the fixed time slice each process gets in Round Robin before being preempted; it has no effect on the other policies. Count (2 to 7) sets how many processes are generated, and Speed scales the animation playback rate without changing the result.
What is the difference between SJF and SRTF?
SJF is non-preemptive: once a process begins it runs to completion, and the scheduler only chooses again when the CPU is free. SRTF is the preemptive form: every unit it picks the available process with the smallest remaining time, so a newly arrived shorter job can interrupt the running one.
How are turnaround and waiting time calculated?
For each process, turnaround time equals completion time minus arrival time, and waiting time equals turnaround time minus burst time. The averages shown update live as the cursor reveals completed processes, so you can watch the figures settle as the Gantt chart fills in.
Why does Round Robin produce so many context switches?
Round Robin preempts the running process whenever its quantum expires and sends it to the back of a circular queue. With a small quantum the CPU changes process frequently, which improves response time and fairness for interactive workloads but raises the context-switch count, each one carrying real overhead in a true system.
What is the convoy effect and how can I see it here?
The convoy effect occurs under FCFS when a long CPU-bound process arrives first and several short processes queue behind it, inflating their waiting times. Randomise until a long job arrives early, run FCFS, then switch to SJF on the same set: the average waiting time usually drops sharply.
Does the simulation model preemption and idle CPU time?
Yes. SRTF and Round Robin are genuinely preemptive in the model, and when no process has arrived yet the timeline records an idle unit shown as a faint block. Those idle gaps are still counted in totalTime, so they correctly delay the completion and turnaround of later processes.
How does the Priority policy decide what runs?
Each process is assigned a priority number, and the scheduler runs the available process with the lowest number, treating that as the highest priority. It is non-preemptive here, so a chosen process finishes before the next decision. Without aging this scheme can let a low-priority process starve if higher-priority work keeps arriving.
Is this an accurate model of a real operating-system scheduler?
The algorithms match the textbook definitions taught in operating-systems courses, with integer time units and known burst lengths. Real schedulers add complications such as unknown future bursts, I/O blocking, multiple cores, priority aging and per-switch overhead, so this is an accurate teaching model rather than a faithful reproduction of a production kernel.
Schedule processes on a CPU with FCFS, SJF, priority and round-robin policies. An animated Gantt chart shows context switches while average waiting and turnaround times update live.
3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install