🖥️ 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.