22 min read
Process and Memory Management
Processes, multitasking and scheduling, interrupts, and how the OS shares and protects memory.
Processes
A process moves between three main states:
- Running — it is using the CPU now.
- Ready — it could run, and is waiting its turn for the CPU.
- Blocked (waiting) — it is waiting for something else, such as a file to load or the user to type.
Process states
Multitasking and Scheduling
A single CPU core can only run one instruction stream at a time. The OS creates the illusion of many programs running together by switching between them very quickly — this is multitasking. The part of the OS that decides which process runs next is the scheduler.
Common scheduling methods:
- Round robin — each process gets a short, equal time slice in turn.
- Priority — more important processes (such as the mouse pointer or a video call) go first.
- First come, first served — processes run in the order they arrive (used for print queues).
With several cores, the OS can run several processes truly at the same time.
Memory Management
The OS keeps track of every part of RAM:
- It allocates memory to a process when it starts and frees it when the process ends.
- It protects each process's memory, so one program cannot read or overwrite another's — a crash in one app does not bring down the others.
- When RAM is full, it uses virtual memory: it moves pages of memory that are not being used to the storage drive (paging), and brings them back when needed.
If the computer spends more time moving pages than doing useful work, it becomes very slow. This is called thrashing — a sign that the computer needs more RAM.
Practice
More lessons in Operating Systems · Next: File, Device and Security Management · Previous: What an Operating System Does
