Part 1 of 6 · 1 min read
Why this page comes fifth
In this module you will
- List the steps the kernel takes to switch from one process to another.
- Say what is saved, where it is saved and what is restored.
- Tell a context switch from a mode switch.
- Measure the cost of a context switch with a pipe ping-pong program.
- Name the hidden costs that make a switch more expensive than the copying alone.
Pages 1 and 2 said a process has registers, memory and a state, and that the kernel keeps them in a process control block. Page 2 also said a running process can lose the processor. This page shows exactly how that happens, step by step. Without the switch, multiprogramming (Level 0, page 1) would not work, and the scheduling levels that follow only decide who goes next, while this page covers how the change is made. The main sources are "Operating System Concepts" (OSC), chapter 3, "Operating Systems: Three Easy Pieces" (OSTEP), chapter 6, and "Modern Operating Systems" (MOS), chapter 2.
About this example About this example
Real: The C programs, commands and outputs on this page were compiled with gcc -Wall -Wextra -pthread and run on a Linux test machine (2 processors, kernel 6.18, glibc 2.39).
Scripted: The worked traces use small numbers chosen so they can be followed by hand.
Not real: The page simplifies real systems. Actual kernels add more cases, limits and tuning than a short page can show.