Skip to content

1/32 · 5 min

Eight programs, four cores, no waiting

Open your laptop and look at what is running. A browser with fourteen tabs. A music player. Something checking for updates. A terminal. The window manager drawing all of it.

Now open the system monitor and count the processor cores. Four, probably. Perhaps eight.

More than a hundred processes. Eight places to run. Nothing appears to be waiting.

The trick

Every one of those programs was written as though it owns the machine. Your C program says int x = 5 and expects the memory at that address to be its own. It calls printf and expects the screen. It never asks permission and never checks whether something else is using the processor.

That works because an operating system spends its entire life maintaining an illusion for each of them:

The program believesThe truth
It has the processor to itselfIt gets a few milliseconds at a time
It has its own memory from address 0Its addresses are translated on every access
It can read a file directlyIt asks the kernel, which decides
It is the only thing runningIt is one of a hundred and forty

Why the illusion has to be perfect

If it slipped, every program would need to be written to cope. Your first C program would need to check whether another process wanted the processor, negotiate for memory, and take turns with the disk.

Nobody could write anything. So the operating system does not merely help with these things: it makes them impossible to get wrong, by not letting a program near them at all.

Scheduling maintains the illusion of a private processor. Virtual memory maintains the illusion of private memory. File systems maintain the illusion that a spinning platter is a folder tree.

Eight programs, four cores, no waiting