browseruser modemusicuser modenotesuser mode1f = open("list.txt", "w")2f.write("milk")3f.close()kernel mode · full control of the hardwareschedulermemoryfilesdriversCPUbrowsermusicnoteslist.txt
Top: the apps, each a running program (a process)Middle: the OS kernel and its parts: scheduler, memory, files, driversBottom: the hardware it manages: CPU, memory, disk, speakerThree layers: the apps at the top, the OS kernel in the middle and the hardware at the bottom. Each part of the kernel stands above the hardware it manages. Programs are copied from the disk into memory and run as processes, take turns on the CPU, and stay inside their own memory. To use the disk or the speaker, an app asks the kernel with a system call, and a driver does the talking. Most CPUs today have several cores, and each core runs one process at a time, so a few processes really do run at the same moment. The OS still switches every core between many processes.

The layers

  1. At the bottom is the hardware: the CPU (processor) that carries out instructions, memory (RAM) that holds running programs, a disk that keeps files, and devices such as a speaker. Many programs want these parts at the same time.

Running programs

Asking the OS

What happens

;; step 1/10 · hardware
hardware   the parts you can touch
  CPU      carries out instructions, one after another
  memory   RAM: holds the programs that are running
  disk     keeps files, even when the power is off
  speaker  one of many devices (screen, keyboard, Wi-Fi ...)
every app wants to use them, all at once

Most CPUs today have several cores, and each core runs one process at a time, so a few processes really do run at the same moment. The OS still switches every core between many processes. How long a time slice lasts depends on the OS and on how busy the computer is. The OSTEP textbook uses a timer that interrupts every 10 milliseconds as its example, which would allow about 100 switches a second.