What actually happens between your code and the hardware. Four weeks on the three jobs every OS does — sharing the CPU, sharing memory, and storing things that survive a power cut — ending where it matters to you: how virtual machines and containers really work.
Strip away the jargon and an OS has one job: stand between your programs and the hardware, and make a messy, singular, physical machine look like a tidy set of private, abstract resources to everyone who asks. It's part referee, part illusionist.
Everything the OS does falls into one of two buckets:
The whole course is really three deep dives into that illusionist role: making one CPU look like many (Week 1–2), making limited memory look private and infinite (Week 3), and making volatile hardware look like permanent, named storage (Week 4).
The most important boundary in any computer. Code runs in one of two modes:
This divide is enforced by the CPU itself, not by politeness. It's why one crashing app doesn't take the whole machine down, and why malware can't (easily) read another program's secrets. The caging is the feature.
But a caged program still needs to do real things: read a file, send a packet, start another program. It does this by asking the kernel through a system call — a controlled doorway between user and kernel mode.
A system call is a deliberate, hardware-assisted "trap": the program sets up its request, executes a special instruction, and the CPU jumps into kernel mode at a fixed, trusted entry point. The kernel checks the request, does the privileged work, and hands control back. It's the airlock between the cage and the machine room — the only sanctioned way through.
A program is a dead thing — a file on disk. A process is that program brought to life and running: it has memory, open files, a slice of CPU time, and a current position in its own execution. The process is the OS's fundamental unit of "a running thing."
The OS tracks each process in a bookkeeping record (the process control block): its unique ID, its current state, the contents of the CPU registers when it last paused, its memory layout, and its open files. That register snapshot is the key to the magic trick we'll see next — it's a complete "bookmark" of a running program.
At any instant a process is in one of three states, and it dances between them constantly:
Click through the transitions — this little state machine is the heartbeat of every computer you've ever used:
On Unix-like systems (Linux, macOS, Android under the hood) new processes are born a surprising way: a process clones itself with fork(), producing a near-identical child, which then replaces its own program with exec(). Clone, then transform.
pid_t pid = fork(); // clone this process in two
if (pid == 0) {
// child: become a different program
execlp("ls", "ls", "-l", NULL);
} else {
// parent: wait for the child to finish
wait(NULL);
}Every process descends from another, forming a tree rooted at the very first process the kernel starts at boot. It's turtles all the way down to init.
Your laptop runs hundreds of processes on a handful of cores. It does this with a magic trick (time-sharing) and a hard problem (keeping things correct when they overlap). Week 2 is both halves.
A single CPU core does exactly one thing at a time. The appearance of many simultaneous programs comes from switching between them fast — thousands of times a second, faster than you can perceive. Each switch is a context switch:
To pause process A and run process B, the OS saves all of A's CPU registers (its exact bookmark) into A's control block, loads B's saved registers, and resumes. When A's turn comes again, it continues as if nothing happened — it has no idea it was ever paused. The register snapshot is the running program's soul; save and restore it, and you can juggle hundreds.
Switching isn't free — it costs a little time and throws away warm caches — so the OS balances switching often (responsive) against switching rarely (efficient).
A thread is a line of execution within a process. One process can have many threads, and crucially they share the same memory. That makes threads cheap to create and great for parallel work — and simultaneously the source of the hardest bugs in computing, because shared memory means they can step on each other.
When the CPU comes free, the scheduler picks which ready process runs. Different algorithms optimise for different things:
| Algorithm | Rule | Strength / weakness |
|---|---|---|
| FIFO / FCFS | First to arrive runs first, to completion | Simple; but one long job stalls everyone ("convoy effect") |
| SJF | Shortest job first | Best average wait; but needs to know job lengths, can starve long jobs |
| Round Robin | Each gets a fixed time slice, then rotates | Fair and responsive; more switching overhead |
| MLFQ | Multiple priority queues, jobs demoted as they use CPU | What real systems use — learns who's interactive vs batch |
Run the same four jobs through different schedulers and watch the trade-off in the timeline and the average wait:
When two threads touch the same data at the same time, results depend on the exact interleaving of their steps — which is unpredictable. This is a race condition, and it's the bug that only appears in production, at 2am, once a week.
Imagine two threads each doing balance = balance + 100 on a shared account. That one line is secretly three steps: read balance, add 100, write it back. Interleave them badly:
The code looks correct. It is correct, run alone. It's only wrong when it overlaps — which is exactly what makes these bugs so maddening.
The overlapping region (the "critical section") must be made indivisible — only one thread inside at a time. The tool is a lock (mutex):
lock(&account_mutex); // wait until it's mine alone
balance = balance + 100; // critical section — safe now
unlock(&account_mutex); // let the next thread inOther tools build on this idea: semaphores (count a limited resource — "5 free slots"), and condition variables ("sleep until this becomes true"). But they all serve the same goal: tame the interleaving.
Locks solve races but introduce a new hazard. Thread A holds lock 1 and wants lock 2; thread B holds lock 2 and wants lock 1. Both wait forever. That's deadlock, and it needs four conditions all at once — break any one and you're safe:
The easiest condition to break is circular wait: always acquire locks in a fixed global order. If every thread grabs lock 1 before lock 2, the cycle can never form. A simple convention beats clever detection.
Every program believes it owns a huge, private, contiguous block of memory starting at address zero. That belief is a lie the OS and hardware maintain beautifully — and it's what stops programs corrupting each other while squeezing them all into limited physical RAM.
Physical memory is one finite array of bytes, shared by everything. Without help, program A could read or clobber program B's data, programs would fight over the same addresses, and nothing would fit once RAM filled. Virtual memory fixes all three at once.
The trick: programs only ever use virtual addresses. Every memory access is translated, in hardware, to a real physical address on the fly — by a dedicated chip called the MMU (memory management unit). Program A's address 0 and program B's address 0 map to different physical locations, so they're invisible to each other. The illusion of a private machine, enforced per access.
Rather than translate every byte, memory is chopped into fixed-size pages (typically 4 KB). Physical memory is chopped into equal frames. A per-process page table records which physical frame holds each virtual page. Translation splits an address in two:
Slide a virtual address and watch it get translated, exactly as the MMU does billions of times a second:
Looking up the page table on every access would be ruinously slow. So the MMU keeps a small cache of recent translations — the TLB (translation lookaside buffer). Hit the TLB and translation is nearly free; miss it and you pay for the full lookup. Most programs hit ~99% of the time, which is why virtual memory costs almost nothing in practice.
Here's where the "infinite memory" illusion comes from. Not every page needs to be in RAM — rarely used pages can sit on disk. When a program touches a page that isn't currently in RAM, the MMU raises a page fault: the OS pauses the program, fetches the page from disk into a free frame, updates the page table, and resumes. The program never knows it happened — it just ran a little slower that once.
When RAM is full and a new page must come in, something has to go. Which page you evict matters enormously — evict one you'll need immediately and you'll just fault it back in (a disaster called thrashing). The classic policies:
Feed the same sequence of page accesses to both and count the faults — LRU usually wins:
CPU and memory are fast and forgetful — pull the plug and they're blank. The last job of the OS is to manage slow, permanent storage and give it a clean face: files and directories. This week also lands where your working life does — virtual machines and containers.
Disks, networks, and keyboards are glacially slow next to the CPU. The OS could sit and repeatedly ask "done yet? done yet?" (polling — wasteful), or it could issue the request, go do other work, and let the device interrupt it when finished. Interrupts are how a computer stays productive while waiting on the physical world — the CPU fires off a disk read and schedules other processes until the "I'm done" signal arrives.
Moving a big file byte-by-byte through the CPU would waste it entirely. Direct memory access lets a device copy data straight into RAM on its own, interrupting the CPU only once at the end. The CPU delegates the grunt work and stays free for real computation.
A disk is really just a huge numbered array of fixed-size blocks. The OS hides that behind the file: a named, arbitrarily-sized, growable sequence of bytes, organised in a tree of directories. You say "append to report.txt"; the OS figures out which physical blocks that means, allocating new ones as needed.
On Unix-style file systems, each file has an inode — a record holding everything about the file except its name: its size, permissions, timestamps, and the list of disk blocks holding its data. The name lives in the directory, which just maps names to inode numbers. A neat consequence: the same file can have two names (hard links) because two directory entries can point at one inode.
What if the power dies mid-write? You could be left with a half-updated file system — a corrupted mess. Modern file systems prevent this with a journal: before making a change, they first write down their intent in a dedicated log. After a crash, the OS replays the journal to finish or discard half-done operations. It's the write-ahead log idea — the same trick databases use to never lose a committed transaction.
Write-the-intent-first, then act, then confirm — journaling for file systems, write-ahead logs for databases, idempotent retries for payments. The same reliability pattern recurs at every layer of a system, including the ledgers in a lending platform.
Every concept so far — the kernel boundary, virtual memory, the process, the file system — comes together in the two technologies your infrastructure runs on. Understanding the difference is understanding your whole deployment stack.
A VM takes the OS's illusionist trick up a level: a hypervisor makes one physical machine present itself as several complete virtual machines, each running its own full OS, kernel and all, believing it owns real hardware. Strong isolation (each has its own kernel), but heavy — you're running many complete operating systems, each with its own memory and boot time.
Containers are lighter and cleverer. They share the host's single kernel but use two kernel features to make each container feel like it has the machine to itself:
| Virtual machine | Container | |
|---|---|---|
| Virtualizes | The hardware | The operating system |
| Kernel | One per VM | Shared host kernel |
| Isolation | Very strong | Strong, but shared-kernel |
| Start time | Seconds to minutes | Milliseconds |
| Overhead | Heavy (full OS each) | Light (just your process) |
A VM is a whole computer pretending to exist; a container is a process wearing a convincing disguise. VMs isolate by duplicating the OS; containers isolate by namespacing a shared one — which is why a container boots in milliseconds and a VM doesn't.
From the kernel boundary and the system-call airlock, through processes and the context-switch bookmark, the scheduler and the locks that tame concurrency, virtual memory and the page fault, down to files, inodes, journaling, and the VMs and containers your platform runs on — you now have the mental model of what happens between your code and the silicon. Every performance mystery, every weird production bug, every infrastructure choice makes more sense from here.