The kernel is the core of an operating system: the one program that talks to the hardware directly and decides which app gets the CPU, memory and devices, how much, and when.
Every app you run depends on it, and knowing how it works explains why one app's crash rarely takes the others with it, and why containers start so quickly.
Why apps can't touch the hardware
If every app could drive the hardware itself, one bug could wreck everything. A game could overwrite the memory your browser is using, or a buggy app could scribble over the disk's file table halfway through a save. Worse, a malicious program could read another program's passwords straight out of RAM.
Modern CPUs prevent this with privilege levels. Code runs in one of two modes:
- Kernel mode: full access to every instruction, memory address and device.
- User mode: restricted. The CPU refuses privileged instructions and only lets the program reach memory it has been given.
The kernel runs in kernel mode. Everything else runs in user mode: your browser, your editor, even a program started as root or administrator. On x86 these levels are called rings, with ring 0 for the kernel and ring 3 for apps. The memory the kernel keeps for itself is called kernel space, and everything else is user space.
How an app asks: system calls
An app that needs something only the hardware can give makes a system call: a request to the kernel through a small set of defined entry points. Opening a file, sending a network packet, starting a new process, asking for more memory and reading the clock are all system calls. Linux has a few hundred of them.
You rarely make one by hand, because your language's standard library does it for you. This Python looks like ordinary code:
with open
Wondering how this was made? How we make these