Menu

Process Management

CPU Scheduling and Time Slices

On a single-core CPU only one process can be carried out at any instant, because the core can only work through one instruction at a time. So that every program you are using keeps making progress, the operating system shares the CPU out, letting processes take turns.

Time slices

A time slice is the small amount of CPU time the operating system gives a process before moving on, often just a few milliseconds. When a process's time slice runs out, it is paused and a different process gets a turn.

  • A slice that is too long lets one process hog the CPU, so other programs stall and the computer seems to freeze.
  • A slice that is too short means the CPU spends much of its time switching between processes instead of doing useful work.

The scheduler

The scheduler is the part of the operating system that decides which process runs next and how long its time slice will be. The rules it follows are called a scheduling algorithm. One algorithm might be fair so every process gets a turn; another might let the process you are using run first, so the computer feels responsive.

The scheduler only makes the decision. The CPU is the hardware that actually carries out the process. This constant switching between processes is what makes multi-tasking possible.

Worked example

Imagine a single-core computer running three processes: the text editor you are typing into, a video editor exporting a clip and a zip program compressing a folder, with each process given a 15 ms time slice.

TurnTime on the CPU (ms)Process running
10 to 15Text editor
215 to 30Video export
330 to 45Zip compression
445 to 60Text editor

A timeline from 0 to 60 ms on a single-core CPU split into four 15 ms time slices: the text editor (0 to 15), video export (15 to 30), zip compression (30 to 45), then the text editor again (45 to 60).

Each process gets a regular turn, and because the switching happens so quickly the letters you type still appear straight away while the export and the compression carry on in the background.

Practise this