Processes and threads
Introduit| English | Sens |
|---|---|
| operating systems | operating systems |
| process/ˈprəʊses/ | An instance of a program in execution together with its execution state and allocated resources. |
| states/steɪts/ | The possible configurations or conditions of a system at a particular point in its operation. |
| ready | ready |
| running | running |
| blocked/blɒkt/ | blocked |
| thread | An execution flow inside a process — shared space, own stack. |
| process control block/ˈprəʊses kənˈtrəʊl blɒk/ | An operating-system record containing the state and management information associated with a process. |
| context switch/ˈkɒntekst swɪtʃ/ | Saving one task's execution state and restoring another's so the processor can change which task it runs. |
The first illusion
- An operating systems layer turns one processor into many machines. A process is a program in motion: its own address space, registers, open files.
- A process lives through five states: new, ready (waiting only for the CPU), running, blocked (waiting on a device), terminated. A thread is an execution flow inside a process — shared space, own stack.

{exercise:uni-cs0701-states}
A process waiting for disk I/O is —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Blocked waits on a device; ready waits only for the CPU.
The PCB and the switch
- To suspend a process the OS saves the process control block — registers, program counter, page-table pointer, open files. The context switch is exactly this save-and-restore.
- With course timings, saving and restoring $2000$ bytes at $2$ GB/s costs $1$ µs — plus cache pollution. Switching threads skips the address space (shared), so it is the cheaper switch.
{exercise:uni-cs0701-switch}
Switching threads is cheaper than switching processes because threads —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
Threads share the address space, so the switch skips it — only stacks and registers move.
A fault's journey, and threads' price
- Process A faults on a page: running to blocked (disk); the scheduler dispatches B; the disk completes; A becomes ready; later running again — the faulting instruction restarts, so no work is lost.
- A web server spawns a thread per connection: shared cache, about $50$ µs create-and-switch; as processes, about $500$ µs. Sharing is the thread's point — and unit 7.3's danger.
Blocked is not ready: blocked waits on a device; ready waits only for the CPU.
{exercise:uni-cs0701-thread}
A crashed thread takes with it —
Difficulté 1/5 · 100 pièces + un petit bonus lors de la première réussite aujourd'hui
One address space: a thread crash is a process crash.