CPU Scheduling Algorithms

Master how the Operating System decides which process runs next to maximize CPU utilization and responsiveness.

What is CPU Scheduling?

In a multi-programming environment, multiple processes exist in the memory simultaneously. The primary goal of an operating system is to maximize CPU utilization by switching the CPU among processes efficiently.

When the CPU becomes idle, the short-term scheduler picks from processes in the ready queue and allocates the CPU to one of them.

Core Scheduling Metrics

  • Arrival Time (AT): When a process enters the ready queue.
  • Burst Time (BT): Time required for execution on the CPU.
  • Turnaround Time (TAT): Exit Time - Arrival Time.
  • Waiting Time (WT): Turnaround Time - Burst Time.

The 4 Core Algorithms

1. FCFS (First Come First Served)

The simplest scheduling algorithm. The process that arrives first is executed first. It is non-preemptive.

Pros: Extremely simple to implement.
Cons: Suffers from the "Convoy Effect" (long processes block small ones).

2. SJF (Shortest Job First)

Picks the process with the smallest remaining burst time. Can be preemptive or non-preemptive.

Pros: Optimal for minimizing average waiting time.
Cons: Extremely hard to predict burst time; risks starvation.

3. Priority Scheduling

Processes are assigned priorities. The CPU is given to the process with the highest priority first.

Pros: Critical and urgent system tasks run immediately.
Cons: Low priority tasks may starve without "Aging".

4. Round Robin (RR)

Assigns a fixed "Time Quantum" to each process cyclically. Highly preemptive and fair.

Pros: Great response time, perfectly fair, no starvation.
Cons: High context switching overhead if quantum is too small.

Ready to Understand Them Visually?

Don't just read about them. Use our interactive visualizer to step through FCFS, SJF, Priority, and Round Robin on your own custom processes. Watch the Gantt chart build in real-time.

Launch Interactive Visualizer →