Operating Systems8h estimated

Processes & Threads

Difficulty
Importance

The problem

A computer runs many programs at once on a limited number of CPU cores, and each program needs to be isolated from the others' bugs and memory while still being able to run seemingly simultaneously — the operating system needs a unit of isolation and a unit of concurrent execution.

Why now

Memory, the stack & the heap explained how a single program organizes its own memory, but said nothing about how the machine runs many programs at once without them corrupting each other. A process is the OS's answer to isolation; a thread is its answer to concurrency within that isolation boundary.

Mental model

A process is a sealed box: its own memory, its own address space, unable to see into another process's box without explicit permission. A thread is a worker inside that box — multiple threads in one process share the same memory, so they can cooperate cheaply, but that sharing is exactly what makes concurrency bugs possible.

Requires

Unlocks

Used in

Projects

  • Write a small program that spawns multiple threads incrementing a shared counter without synchronization, and observe the incorrect final result
  • Use your OS's process monitor (Activity Monitor, top, Task Manager) to identify how many threads a running application uses

Examples

  • Opening two browser tabs typically starts two separate processes, so a crash in one doesn't take down the other
  • A web server handling 100 simultaneous requests with 100 threads shares one process's memory across all of them

Resources

Mastery checklist