Dozens of programs are open but the machine has only a few cores — so how do they all appear to run at once? Let many customers take very fast turns at one counter and, from outside, it looks simultaneous.
See this first in FoundationsCan a computer do something else while it waits?Dozens of programs are open on your machine right now. With one core, how can they all appear to run at once? By switching very quickly. This chapter covers what a process is and why the OS goes to such lengths to isolate them.
A program is a file on disk — dead. Run it and the OS loads it into memory, sets up a stack and heap, and points the PC at the first instruction. That living thing is a process. Run the same program twice and you get two processes with separate memory.
Every process gets its own stack and heap, and the OS shows each one a private map (virtual memory) in which "all of memory is yours". Address 100 in A and address 100 in B are different physical memory, so A cannot corrupt B. That isolation is the point of processes.
Inside the OS a scheduler decides who runs next. When a process waits on IO another goes on immediately; if nobody yields, the OS forces a switch every few milliseconds. Watch the CPU0 chip hop between rows below — not simultaneous, just fast.
Creating a process means building a whole memory space. Sharing data requires OS-mediated IPC. Switching swaps memory maps. Those costs are exactly why threads appear in chapter 8.
To create a process the OS must build an address space, set up page tables, and prepare kernel structures such as the file descriptor table. That is why process creation is far more expensive than the thread creation we will see next. And yet that same preparation is why one broken process leaves the others untouched. The reason it is expensive and the reason it is safe are the same reason.
Being heavy did not make processes obsolete. Browsers isolate tabs into processes and containers take the process boundary as their unit for exactly this reason. When a crash on one side must not take everything down, isolation is worth paying for. Heavy is not the same as wrong — what matters is what you are buying with the price.
Try it in the simulator
Terms in this chapter
Why it evolved this way
Early machines ran one program at a time, and the expensive CPU sat idle whenever that program waited for tape or disk. Loading several programs at once and interleaving them removed the waste, and isolation grew up alongside it so they could not wreck each other.
A process = one isolated memory space + one flow of execution. Not simultaneous — taking turns.
The remaining problem
But what does "switching" actually mean? How does a stopped program resume later, and when does the CPU actually rest? →