Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Operating Systems

    The Whole Story

    The whole module retold as one story — no new facts, a fast revision of Operating Systems.

    Extra: Revision3 min read

    A computer is a hotel, and the operating system is its manager (Ch 1). The manager's own office — the kernel — has keys to everything; guests (programs) live in user space and must phone the front desk with a system call for anything that touches the building, because the CPU itself keeps those doors locked (Ch 2).

    Each guest gets a private room: a process with its own PID, memory, open files and saved CPU state (Ch 3). Hundreds of guests share a few courts (cores), so the scheduler gives each a short turn, context switching between them, and never lets one hog the court (Ch 4). Taking turns on one core is concurrency; truly running at once on many cores is parallelism.

    Every guest's booklet uses the same room numbers — virtual addresses — but the front desk's secret page table maps them to different real rooms in RAM, so nobody can reach anyone else's memory (Ch 5). When real RAM runs short, pages go to swap, and if even that fails, the OOM killer removes a guest — exit code 137 in Kubernetes.

    Inside its room, a program keeps quick, short-lived papers on a spike (the stack of function frames) and long-lived papers on a big table (the heap, cleaned by the garbage collector) (Ch 6). A family can share one room as several threads — cheaper than extra rooms, sharing the heap but each with its own stack (Ch 7).

    Sharing brings danger: two people updating one whiteboard lose updates — a race condition — unless only the holder of the marker (lock) may update, or the update is atomic (Ch 8). And if two cooks each hold one tool and wait for the other's, they deadlock forever — unless everyone picks up tools in the same order (Ch 9).

    The disk is a notebook of blank pages; the file system adds the index that turns blocks into files and folders, and each opened file becomes a small file descriptor number. A successful write may still only be in RAM (the page cache) until fsync (Ch 10).

    Most programs spend their lives waiting for disk and network. Rather than a cashier per customer (blocking I/O with a thread each), an event loop hands out buzzers — one thread watching thousands of connections with epoll/kqueue — as long as nobody blocks the cashier with heavy work (Ch 11).

    Finally, the manager can slip notes under doors — signals — asking politely (SIGTERM) or ordering immediate removal (SIGKILL), which is how servers are shut down gracefully during deployments (Ch 12).

    The next files connect this hotel to the outside world: how one computer finds and talks to another — networking.