You run a small C program with a bug in it. The window prints "Segmentation fault" and the program is gone. Now look around. The music player is still playing, the browser still has all your tabs, and the clock in the corner is still ticking. One program fell over and nothing else even noticed. That is not luck. Something stands between every program and the machine, and it will not let a crashed program, a careless one or a hostile one drag everyone else down with it.
Now press the power button and meet the opposite problem. The computer's memory is empty, no program is running, and yet within a minute you are looking at a login screen. Who started the first program, if there was no program to start it? And in between, whenever you save a file or open a web page, your program has to ask that same guard for permission, because it is not allowed to touch the disk or the network card itself.
This chapter is about that guard, which is called the kernel, and about three conversations you can have with it. How is it built, and why does a program run in a mode that keeps it away from the machine? How does a program ask it for a service? And how does it get started in the first place?
By the end you will be able to say what the kernel does and how it differs from the shell, explain the CPU's two modes and the three ways into the kernel, read a protection table as an ACL or a capability list, compare five kernel designs, follow one system call into the kernel and back, name the six kinds of system call, and put the boot steps in order, from the power button to the login prompt, in Linux and in Windows.