What is an Operating System?
Kernel, Userspace & Hardware
The Big Picture
An operating system is the middleman between you and the raw hardware. Without it, you’d have to manually manage memory addresses, CPU cycles, and disk sectors. The OS abstracts all that complexity away.
The Kernel: Heart of the System
The kernel is the core of any operating system. It’s the only software that talks directly to hardware.
What the Kernel Does:
- Process Management: Runs multiple programs “simultaneously” (time-slicing)
- Memory Management: Gives each program its own memory space
- Device Drivers: Translates for hardware (keyboard, disk, GPU)
- Filesystem: Organizes data on storage devices
- Networking: Handles TCP/IP, sockets, packets
Linux Kernel Architecture:
┌─────────────────────────────────────────────┐
│ USER SPACE │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Firefox │ │ VS Code │ │ Terminal│ ... │
│ └────┬────┘ └────┬────┘ └────┬────┘ │
│ │ │ │ │
│ ═════╧═══════════╧═══════════╧═════════════│
│ System Call Interface │
│ ═══════════════════════════════════════════│
│ KERNEL SPACE │
│ ┌──────────┬──────────┬──────────┐ │
│ │ Process │ Memory │ VFS │ │
│ │ Scheduler│ Manager │(Filesys) │ │
│ └──────────┴──────────┴──────────┘ │
│ ┌──────────────────────────────────┐ │
│ │ Device Drivers │ │
│ │ (disk, network, GPU, USB...) │ │
│ └──────────────────────────────────┘ │
└─────────────────────────────────────────────┘
│
┌───────┴───────┐
│ HARDWARE │
│ CPU RAM DISK │
└───────────────┘
User Space: Where You Live
Everything above the kernel is user space:
- Shell (bash, zsh): The command interpreter
- Desktop Environment (GNOME, KDE): The graphical interface
- Applications: Firefox, LibreOffice, VS Code
- System Libraries (glibc): Shared code used by programs
User programs can’t touch hardware directly. They make system calls to ask the kernel nicely.
Monolithic vs Microkernel
Linux uses a monolithic kernel: drivers run inside kernel space for performance.
Microkernels (like MINIX, Mach) run drivers in user space — more stable but slower.
MONOLITHIC (Linux) MICROKERNEL (Mach)
┌────────────────┐ ┌────────────────┐
│ User Space │ │ User Space │
├────────────────┤ │ ┌──────────┐ │
│ │ │ │ Drivers │ │
│ Kernel │ │ └────┬─────┘ │
│ + Drivers │ ├───────┼────────┤
│ │ │ Microkernel │
└────────────────┘ └────────────────┘
Faster More Stable
Systems Engineering Perspective
Think of your computer as a bustling city, and the OS as its government:
The OS as Resource Manager
CPU Scheduling → Air Traffic Controller
- Many processes want to run, but there’s only a few CPU cores
- The scheduler gives each process tiny time slices (milliseconds)
- You never notice because it switches thousands of times per second
- Priority system: critical processes get more time
Memory Management → Librarian
- Limited shelf space (RAM) for many books (programs)
- Virtual memory: each program thinks it has the whole library to itself
- Swap space: store rarely-used books in the basement (disk)
- When a program crashes, the librarian keeps other programs’ books safe
Device Drivers → Translators
- Your mouse speaks “USB HID protocol”
- Your disk speaks “SATA commands”
- The kernel translates these into a common language programs understand
- Analogy: Like a UN translator converting between languages
Abstraction Layers
Each layer hides complexity from the layer above:
┌──────────────────────────────┐
│ Applications │ → "Save this file"
├──────────────────────────────┤
│ System Libraries (glibc) │ → "Write bytes to fd 3"
├──────────────────────────────┤
│ System Calls │ → write(3, buffer, size)
├──────────────────────────────┤
│ Kernel (VFS Layer) │ → Translate to filesystem ops
├──────────────────────────────┤
│ Filesystem Driver (ext4) │ → Translate to block writes
├──────────────────────────────┤
│ Block Device Driver │ → Send SATA commands
├──────────────────────────────┤
│ Hardware Controller │ → Physical disk write
└──────────────────────────────┘
Each layer knows nothing about the layers below — that’s abstraction.
Trade-offs Everywhere
Performance vs Safety
- Kernel mode: Fast but dangerous (one bug crashes everything)
- User mode: Slower but safe (crashes isolated to one program)
- Why sudo is powerful: temporarily grants kernel-level access
Flexibility vs Complexity
- More features = more code = more bugs
- Linux kernel: ~30 million lines of code
- Every new feature is a security surface
Isolation vs Efficiency
- Processes: Completely isolated (safe) but slow to create
- Threads: Share memory (fast) but can interfere with each other
The OS is basically a very sophisticated referee that keeps your programs from fighting over resources like toddlers over toys. It enforces fair sharing, prevents bullying, and sends troublemakers to timeout (kills crashed processes).
“Everything is a File”
This is Linux’s most powerful idea. Almost everything is represented as a file:
| Path | What It Represents |
|---|---|
/dev/sda | First hard disk |
/dev/null | Black hole (discards data) |
/dev/random | Random number generator |
/proc/cpuinfo | CPU information |
/sys/class/net/ | Network interfaces |
You can read CPU temperature, control LED brightness, or check battery status — all by reading/writing files.
Why This Matters
Understanding the OS architecture helps you:
- Debug problems: Know where to look (kernel? driver? application?)
- Optimize performance: Understand what’s actually happening
- Appreciate the design: 50+ years of Unix wisdom