← back to Operating Systems

Scheduling

Wikipedia · wpScheduling (computing) · CC BY-SA 4.0

The scheduler decides which process gets the CPU next. The algorithm determines fairness, throughput, and response time. There is no single best policy: every choice is a tradeoff.

First-Come, First-Served (FCFS)

The simplest policy: processes run in arrival order. No preemption. Problem: a long job blocks everyone behind it (the convoy effect).

Shortest Job First (SJF)

Run the process with the shortest burst time next. Optimal for minimizing average waiting time, but requires knowing burst lengths in advance. In practice, the OS estimates them.

Round-Robin

Each process gets a fixed time quantum. When the quantum expires, the process goes to the back of the ready queue. Good for time-sharing. Small quantum means more context switches. Large quantum degrades to FCFS.

Round-Robin (quantum = 2) P1 P1 P2 P2 P3 P3 0 2 4 6 8 10 12
P1 P2 P3 P1 P2 P3 quantum 0 q 2q 3q 4q 5q 6q each process gets a fixed time slice — fair but not optimal
Scheme

Priority scheduling

Each process has a priority. Highest priority runs first. Risk: starvation of low-priority processes. Solution: aging, which gradually increases priority of waiting processes.

Multilevel queues

Multiple ready queues, each with its own scheduling algorithm. Foreground processes get round-robin. Background processes get FCFS. A multilevel feedback queue lets processes move between queues based on behavior.

Metrics

Turnaround time = completion time minus arrival time. Waiting time = turnaround time minus burst time. Response time = first run minus arrival time. Good schedulers minimize all three, but tradeoffs are inevitable.

Scheme
Neighbors
  • ⚙ Sorting — scheduling is sorting by priority, burst time, or arrival
  • 🎛 Control Ch.3 — PID control: CPU schedulers like CFS use feedback from CPU utilization to adjust time-slice allocation
  • ♟ Game Theory Ch.13 — volunteer's dilemma and priority: scheduler priority queues solve a coordination game about who runs first
  • ⚙ Algorithms Ch.7 — greedy and priority-queue algorithms: EDF and priority scheduling are greedy algorithms on a priority queue

Foundations (Wikipedia)