🖥️ CPU Scheduling
FCFS, SJF, Round Robin
Time 0 / 0
Policy: FCFS
Policy
Processes
Controls
Averages
Avg waiting
0.0
Avg turnaround
0.0
Context switches
0
Status
Ready
Per-process
Info & Theory

CPU scheduling decides which of several ready processes gets the processor next. Each process has an arrival time and a burst time (CPU time needed). The scheduler picks the next process to run.

FCFS

First-Come, First-Served runs processes in arrival order, non-preemptively. Simple, but a long job can delay everyone behind it — the convoy effect.

SJF & SRTF

Shortest Job First picks the ready process with the smallest burst. SRTF is its preemptive form: a newly arrived shorter job preempts the running one. SJF gives the provably minimum average waiting time but can starve long jobs.

Priority

Each process carries a priority (lower number = higher priority here). The scheduler runs the highest-priority ready process. Without aging, low-priority jobs may starve.

Round Robin

Each process runs for at most a fixed quantum, then is preempted to the back of the queue. Great fairness and response time, at the cost of more context switches.

Metrics

  • turnaround = completion − arrival
  • waiting = turnaround − burst

Switch policy on the same process set and compare the averages — the Gantt chart shows exactly where context switches happen.

Frequently asked questions

What is CPU scheduling?

CPU scheduling is the operating-system activity of deciding which ready process gets the CPU next. A scheduling policy chooses among waiting processes to optimise goals like short waiting time, fairness or throughput.

What is the difference between FCFS and SJF?

FCFS (First-Come, First-Served) runs processes in arrival order. SJF (Shortest Job First) picks the ready process with the smallest burst time. SJF minimises average waiting time but can starve long jobs and needs to know burst lengths in advance.

What is the difference between SJF and SRTF?

SJF is non-preemptive: once a process starts it runs to completion. SRTF (Shortest Remaining Time First) is the preemptive version: if a newly arrived process has a shorter remaining time than the running one, it preempts it.

How does Round Robin scheduling work?

Round Robin gives each process a fixed time quantum in turn using a circular ready queue. If a process is not finished when its quantum expires it is preempted and moved to the back of the queue, giving responsive, fair time-sharing.

What is turnaround time?

Turnaround time is the total time from a process arriving to it completing: completion time minus arrival time. It equals waiting time plus burst time.

What is waiting time?

Waiting time is the time a process spends in the ready queue not running. It equals turnaround time minus burst time, and is the metric most schedulers try to minimise on average.

What is a Gantt chart in scheduling?

A Gantt chart is a horizontal timeline showing which process occupies the CPU at each time slice. Context switches appear as boundaries between coloured blocks, making it easy to see the order and duration of execution.

What is the convoy effect?

The convoy effect happens under FCFS when a long CPU-bound process arrives first and many short processes queue behind it, inflating their waiting times. SJF and SRTF avoid it by prioritising short jobs.

Can priority scheduling cause starvation?

Yes. If high-priority processes keep arriving, a low-priority process may never run. Real systems use aging, which gradually raises the priority of long-waiting processes, to prevent starvation.

Which scheduling policy is best?

There is no single best policy. SJF/SRTF minimise average waiting time but need burst predictions and risk starvation; FCFS is simple but suffers the convoy effect; Round Robin gives fair response times for interactive systems at the cost of more context switches.

About CPU Scheduling

Written by MySimulator Team · Reviewed by MySimulator Editorial Review

Last updated: 5 July 2026

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.