Processes & Threads
Learning objective
By the end of this lesson you will be able to explain processes, threads and how the CPU switches between them.
Everything your computer runs — an editor, a browser, a game — is organised by the operating system into processes and threads.
Processes
A process is a program in execution with its own memory, files and state. Running two apps means running two processes.
Process states
- New — being created
- Ready — waiting for the CPU
- Running — executing instructions
- Waiting — blocked on input/output
- Terminated — finished
Threads
A thread is a unit of execution inside a process. One process can have several threads sharing its memory — a browser has one thread per tab plus background threads.
Why threads?
- Share memory easily (unlike separate processes)
- Keep a core busy while another thread waits on I/O
- Do parallel work on multi-core CPUs
The scheduler decides which process or thread runs next, switching between them so quickly that everything seems to run at once.
Practice exercise
Open your task manager (Windows) or activity monitor (macOS) and list five running processes.
Check your understanding
1. Which is a unit of execution inside a process?
2. A process waiting for input/output is in which state?
Self-graded — answer then check below.