Computing Foundations › Inside the Machine › Day 6
Day 6: Operating Systems: What They Do and Why
After this lesson you will be able to explain what an operating system does — kernel vs user space, system calls, processes, virtual memory, filesystems, drivers, and permissions — and use that model to explain why AI and server work runs on Linux and to interrogate your own OS from the terminal.
Hands-on lab for this lesson
Lab files on GitHub: https://github.com/ai-roadmap-365/ai-roadmap-365.github.io/tree/main/labs/sections/computing-foundations/day-006-operating-systems-what-they-do-and
- Get the hands-on files. Clone the labs repository once (you can reuse this clone for every lesson). This works on macOS, Linux, and Windows (PowerShell or WSL):
git clone https://github.com/ai-roadmap-365/ai-roadmap-365.github.io.git cd ai-roadmap-365.github.io - Open this lesson's lab. Move into the directory for this specific day. Every lab lives at the same predictable path — section / subsection / week / day:
cd labs/sections/computing-foundations/day-006-operating-systems-what-they-do-and - Read the lab guide. Open `README.md` in that directory. It lists the exact commands, what each does, the expected output, and how to check your work — read it before running anything.
- Run it and check your work. Follow the README's "How to run" section: run the example first to see the finished result, then complete the numbered exercises in `starter/`, then run the tests. The tests pass (exit 0) only when your work is correct.
bash tests/run_tests.sh # or the test command named in the lab README
You can also open the lab as a local page (works offline, shows the file tree and expected output).
Learning objectives
By the end of this lesson you will be able to:
- Explain why bare hardware is unusable without an operating system, using the manager/illusionist/guard framing
- Distinguish kernel space from user space and describe how the CPU's privilege modes enforce the boundary in hardware
- Trace a system call end to end — what happens when a program opens a file, including the permission check and the file descriptor
- Name the operating system's five core jobs (processes, memory, filesystems, drivers, security) and match each to a real-world symptom or tool
- Recount the honest lineage of today's OS families: Unix 1969 at Bell Labs, BSD and System V, Linux 1991, macOS via NeXT/Darwin, and Windows NT — and place WSL as the bridge
- Explain why server and GPU/AI infrastructure runs overwhelmingly on Linux, and what containers add as OS-level isolation
- Interrogate your own OS from the terminal: kernel version, uptime, user, shell, mounted filesystems, and the top memory-consuming processes
Prerequisites
- Days 1–5 of this course (the layered stack, the CPU, the memory hierarchy, binary, and data representation)
- A terminal on macOS, Linux, or Windows with WSL
Why this matters
-
Essentially all serious AI work runs on Linux — the cloud machines you rent, the GPU clusters that train large models, the servers behind every model API.
-
GPU drivers are kernel components. Installing them is an OS operation.
-
Containers are operating-system isolation features, not a separate technology.
-
“Works on my machine” is an OS-environment problem, almost every time.
-
Today is the map; tomorrow’s processes-and-threads lesson and all of Week 2 walk the territory.
The idea in plain language
Bare hardware is nearly unusable. The CPU from Day 2 will fetch, decode and execute forever, but it has no idea what a file is and no opinion about who owns the bytes it just wrote.
The operating system plays three roles at once:
-
A manager — decides which programs run, when, and with how much memory.
-
An illusionist — gives every program a private CPU, private memory and tidy named files, when the truth is one shared machine and raw disk blocks.
-
A guard — stops programs reading each other’s data or wrecking the hardware.
To do that safely it splits the machine in two:
-
The kernel runs privileged. It can touch any memory and any device.
-
User space runs unprivileged — your browser, your Python scripts, even the desktop. A program there can only compute on its own memory.
-
A system call is the only doorway between them. That boundary is the deepest idea in today’s lesson.
Historical background
-
The 1950s problem was economic. Machines cost millions and sat idle between jobs while humans shuffled punch cards. The first “monitors” ran jobs back to back.
-
The 1960s brought time-sharing — many users at terminals, the machine switching so fast each felt alone.
-
Multics (MIT, General Electric and Bell Labs) pioneered the ideas and grew heavy and late.
-
Unix, 1969, was the reaction: Ken Thompson and Dennis Ritchie built something small at Bell Labs, then rewrote it in C — which made it portable, and portable was the thing nobody else had.
-
Everything descends from that split. BSD and System V from Unix; Linux written fresh by Linus Torvalds in 1991 to the same interface; macOS from BSD via NeXT; Windows down its own line from DOS through NT.
What it is — and what it is not
It is:
- The first real program the machine loads, and the last one still running.
- The permanent intermediary between hardware and every other program.
- A scheduler, a memory manager, a filesystem, a pile of drivers, and a permission system.
It is not:
-
Not the desktop. The windows, the dock and the file browser are ordinary user-space programs. You can run Linux with none of them.
-
Not the applications. A distribution ships thousands; none of them are the OS.
-
Not one thing. “The OS” is a kernel plus a large amount of user-space software that people bundle under the same name.
Why it was created and what problems it solves
-
Sharing the machine. A CPU spends most of its life waiting on memory, disk or network. Without an OS, one program monopolises it while it waits.
-
Protecting programs from each other. On early systems any program could overwrite any memory, and one bug crashed everything.
-
Taming the hardware zoo. Drivers translate each device’s electrical dialect into one standard interface.
-
Making storage human. Files, names, folders and timestamps are an organisational fiction over billions of numbered blocks — so useful we forget it is one.
-
Enforcing ownership. Every login, every “Permission denied”, every
sudotraces to multi-user machines needing a concept of who.
How it works
Kernel space and user space
-
The CPU enforces the split, not politeness. Modern processors run in at least two hardware modes.
-
In kernel mode all instructions and all memory are available.
-
In user mode instructions that touch hardware or remap memory are forbidden — executing one traps straight into the kernel.
-
This is transistor-level enforcement, the same logic you met on Day 1. A user-space program cannot touch the disk any more than a hotel guest can rewire the elevator.
System calls: the only door
-
A few hundred exist on Linux —
open,read,write,closefor files;forkandexecto create and run programs;mmapfor memory;socketfor networking. -
Every language bottoms out here. Python’s
open()is a wrapper that eventually executes the syscall instruction. -
Notice what your program never receives: the disk location of the data, the right to touch the disk, or access to the kernel’s bookkeeping. It gets a number.
-
Every later read hands that number back across the boundary and receives bytes copied into its own memory. The kernel stays in control at every step.
Virtual memory, revisited
-
Day 3 showed the hardware side; this is the OS side. The memory manager gives every process a huge, private, contiguous address space.
-
Per-process page tables map those virtual addresses onto whatever physical pages are free, with the CPU translating on every access.
-
Two processes can both believe they own address 4096 without conflict.
-
Touching memory outside your map ends the process — the segmentation fault.
-
When RAM runs short the OS evicts pages to disk. The machine does not stop; it slows to disk latency, exactly as the Day 3 numbers predict.
-
When a training job dies with an out-of-memory error, that is Linux’s OOM killer choosing a process to sacrifice.
An everyday analogy
Think of a hotel.
| The hotel | The operating system |
|---|---|
| Guests | Programs |
| Rooms | Private address spaces |
| The front desk | The system-call interface |
| Staff-only doors | Kernel mode |
| Room keys | Permissions |
| Housekeeping rota | The scheduler |
-
You never fetch your own towels from the store cupboard. You ask at the desk, and staff who are allowed in there fetch them.
-
The point is not politeness. The staff door is locked. A guest with the best intentions still cannot open it.
Examples in practice
-
Permission deniedis step four of the syscall walk returning an error. -
A segmentation fault is the memory manager catching an address outside your map.
-
A machine that has “run out of memory” and gone slow is swapping — running at disk latency rather than RAM latency.
-
Two programs cannot bind the same port because the kernel owns the port namespace and hands each one out once.
-
nvidia-smifailing after a kernel update is a driver built against the old kernel, because drivers are kernel components.
Implications: security, privacy, performance, scalability, and cost
-
Security: the boundary is the security model. Almost every serious local exploit is a way to get code running on the wrong side of it. Kernel bugs are severe precisely because there is nothing above the kernel to contain them.
-
sudois not a formality. It runs a program with the identity that the permission check cannot refuse. -
Performance: crossing the boundary costs. A system call is far more expensive than a function call, which is why high-throughput code batches its reads and writes rather than making one call per item.
-
Scalability: containers share the host kernel, which is why thousands fit on a machine that would run a handful of virtual machines.
-
Cost: swapping is the expensive failure. A job that fits in RAM and a job that misses by a little differ in wall-clock time by orders of magnitude, and you pay for wall-clock time.
Alternatives: free, open source, and commercial
| Option | Type | Where you meet it |
|---|---|---|
| Linux (Ubuntu, Debian) | Free, open source | Essentially every cloud and GPU machine |
| macOS | Commercial, BSD-derived | Your laptop; a good Unix development environment |
| Windows + WSL2 | Commercial + free | Windows machines running a real Linux kernel in a VM |
| FreeBSD | Free, open source | Network appliances, storage systems |
| Container runtimes | Free, open source | Sharing one kernel among many isolated workloads |
-
Learn Linux. macOS is close enough to be comfortable and different enough to surprise you; the servers you deploy to will be Linux.
-
WSL2 is a real kernel in a lightweight VM, not an emulation layer, which is why it behaves like Linux where earlier attempts did not.
Comparison with related concepts
| Term | What it actually is |
|---|---|
| Kernel | The privileged core: scheduler, memory, drivers, syscalls |
| Operating system | The kernel plus the userland people bundle with it |
| Distribution | An OS packaged with an installer and update policy |
| Shell | An ordinary user-space program that runs other programs |
| Firmware | Code on the hardware itself, running before any OS exists |
When to use it — and when not to
-
You do not choose whether to use an operating system. You choose which one, and how much of it you are willing to understand.
-
Use Linux for anything you will deploy, because that is what you will deploy onto and the differences bite at the worst moment.
-
Use containers when you need the environment reproduced, not merely isolated.
-
Use a virtual machine when you need a different kernel — a different OS family, or kernel-level isolation between untrusted tenants.
-
Embedded and real-time work is the exception. A microcontroller may run no OS at all, and a hard-real-time system may use one that guarantees timing where a general-purpose scheduler cannot.
The AI connection
-
The OOM killer will end your training run long before your code raises an error, and it leaves almost no explanation behind.
-
GPU drivers live in the kernel, so a container needs the driver on the host and a matching runtime inside.
-
Data loaders are syscall-bound. Reading a million small files is a million boundary crossings, which is why formats that pack many samples into one file are so much faster.
-
Your model’s memory question is the OS’s memory question. “Does it fit” means “does it fit in physical RAM or VRAM before the OS starts evicting pages”.
Knowledge check
quiz:
question: "A container running a GPU workload starts fine but reports no devices, while the same image works on another host. What is the most likely explanation?"
options:
- "The host is missing the GPU kernel driver, which the container shares rather than supplies"
- "The container image was built for the wrong CPU architecture"
- "The container was given too little memory to initialise the GPU"
- "Containers cannot access GPUs and a virtual machine is required"
answer_index: 0
explanation: "A container shares the host's running kernel. Drivers are kernel components, so the driver must be present on the host; the image supplies only the user-space runtime that talks to it."
Hands-on exercise
Observe the boundary rather than read about it. Worked through fully in the Day 6 lab directory.
| What you are looking at | Command |
|---|---|
| Which kernel is running | uname -a |
| The distribution around it | cat /etc/os-release (Linux) or sw_vers (macOS) |
| Every system call a program makes | strace ls (Linux) or sudo dtruss ls (macOS) |
| Memory pressure and swapping | vmstat 1 5 or vm_stat |
| A permission check failing | touch /etc/nope |
Expected output
Linux hostname 6.8.0-40-generic x86_64 GNU/Linux
openat(AT_FDCWD, "data.csv", O_RDONLY) = 3
touch: cannot touch '/etc/nope': Permission denied
= 3is the file descriptor — the number from step five of the walk.Permission deniedis step four returning an error.
Validate your work
-
You can name the running kernel version and the distribution separately
-
You traced a simple command and found its
openatcalls -
You can point at a file descriptor in the trace output
-
You triggered a permission failure deliberately and can explain which step produced it
-
bash tests/run_tests.shreports 0 failures
Troubleshooting
-
stracenot found. Install it, or usedtrusson macOS — which needssudoand may need System Integrity Protection considered. -
The trace scrolls past. Pipe it:
strace ls 2>&1 | head -40. -
dtrussprints nothing. macOS restricts tracing system binaries. Trace a program you built instead.
Common mistakes
-
Confusing the kernel version with the distribution version. Ubuntu 24.04 and kernel 6.8 are different numbers about different things.
-
Assuming the desktop is the OS. Stop the desktop and the machine keeps running.
-
Reading
sudoas “ignore the rules”. It is an identity the rules permit.
Practice assignment
-
Trace two programs and compare their system calls: something tiny like
echoagainst something that touches the network likecurl. -
Count the calls with
strace -cand note which dominate. -
Write three sentences explaining why the network program makes so many more, in terms of the boundary rather than in terms of “it does more”.
-
Deliberately exhaust memory in a throwaway VM or container with a small limit, and record what the OS does about it.
Extension challenge
-
Find the syscall in the source. Pick
readand locate its entry point in the Linux kernel tree on GitHub. You are not expected to understand it; you are expected to see that it is ordinary code. -
Measure the cost of crossing. Write two loops that each read a megabyte: one byte at a time, and one in 64 KB blocks. Time both. The ratio is the price of the boundary, and it is larger than most people guess.
-
Compare startup. Time
docker run --rm alpine trueagainst booting a VM with the same job. Explain the difference using the diagram in this lesson.
Quiz
Q1. What is the fundamental difference between kernel space and user space?
- Kernel space is stored on disk while user space lives in RAM
- Kernel space runs privileged; user space must ask via system calls
- Kernel space is for system administrators and user space is for ordinary user accounts
- Kernel space runs faster because it uses a separate, faster processor
Show answer
Answer: B. Kernel space runs privileged; user space must ask via system calls
The split is enforced by the CPU's hardware privilege modes: kernel-mode code may execute any instruction and access any memory, while user-mode programs are confined to their own memory and must cross the system-call boundary for anything more.
Q2. What is a system call?
- A phone-home request an operating system makes to its vendor
- Any function call between two functions in the same program
- How a user-space program requests a service from the kernel
- A message one application sends to another application
Show answer
Answer: C. How a user-space program requests a service from the kernel
A system call is the single doorway between user space and the kernel: the program executes a special instruction that switches the CPU into kernel mode at a kernel-chosen entry point, where the request is checked and serviced.
Q3. When a program successfully opens a file, what does the operating system actually hand back to it?
- The physical disk address where the file's data begins
- A complete copy of the file loaded into the kernel's memory
- Direct read/write access to the disk hardware for that file
- A file descriptor — a small integer used as a ticket for later calls
Show answer
Answer: D. A file descriptor — a small integer used as a ticket for later calls
The kernel keeps all the real bookkeeping and hardware access to itself; the program receives only a file descriptor — a number it hands back across the system-call boundary on every subsequent read or write.
Q4. Which statement about the Unix family history is accurate?
- Unix began at Bell Labs in 1969; Linux is a from-scratch Unix-like kernel
- Linux was created by AT&T in 1983 as the commercial successor to Unix systems
- Unix was derived from Windows NT in the early 1990s
- macOS abandoned its Unix heritage when Apple bought NeXT in 1996
Show answer
Answer: A. Unix began at Bell Labs in 1969; Linux is a from-scratch Unix-like kernel
Ken Thompson and Dennis Ritchie started Unix at Bell Labs in 1969; the family branched into BSD and System V; and in 1991 Linus Torvalds wrote the Linux kernel independently — Unix-like in design, but new code. macOS, via NeXT and Darwin, genuinely descends from the Unix/BSD line.
Q5. Why does virtually all server and GPU/AI infrastructure run on Linux?
- Linux is the only operating system that can run Python programs
- It is license-free at any scale, adaptable, scriptable, and remotely run
- Linux is the only operating system with a graphical desktop
- Laws in most countries require datacenter servers to run open-source software
Show answer
Answer: B. It is license-free at any scale, adaptable, scriptable, and remotely run
Zero per-machine license cost across huge fleets, an open kernel that cloud and GPU vendors can modify, end-to-end scriptability, and remote text-based administration made Linux the default for servers, clouds, and GPU clusters — not fashion or legal mandate.
Q6. What is a container, in operating-system terms?
- A complete emulated computer running its own separate kernel
- A compressed archive format for shipping source code
- A kernel-enforced isolated slice of user space sharing the host kernel
- A physical case that holds multiple separate servers in a datacenter rack
Show answer
Answer: C. A kernel-enforced isolated slice of user space sharing the host kernel
Containers use kernel features (namespaces and control groups on Linux) to isolate processes while sharing the host kernel — lighter and faster to start than a virtual machine, which emulates a whole machine with its own kernel.
Q7. A script works on your laptop but fails on a server with "Permission denied". Which OS subsystem produced that message, and at what moment?
- The compiler, when the script was first written
- The CPU cache, when it ran out of room for the script
- The bootloader, when the server last restarted
- The kernel's permission check, against the file's ownership bits
Show answer
Answer: D. The kernel's permission check, against the file's ownership bits
Permission checks happen inside the kernel during system calls such as open: the caller's user identity is compared against the file's owner and permission bits, and a mismatch returns the error the program reports as "Permission denied".
Q8. What is the relationship between Linux and a Linux distribution such as Ubuntu?
- Linux is the kernel; Ubuntu packages it into a complete product
- Ubuntu is a rival kernel that competes with Linux
- Linux is a graphical desktop that runs on top of Ubuntu
- They are the same thing under two names
Show answer
Answer: A. Linux is the kernel; Ubuntu packages it into a complete product
Linux proper is only the kernel. Distributions like Ubuntu, Debian, and Fedora bundle it with user-space tools and policies — which is why cloud providers offer "Ubuntu" images rather than "Linux" ones.
Glossary
- operating system
- The software layer that manages a computer's hardware and provides common services to programs — a manager of resources, an illusionist providing private-machine fictions, and a guard enforcing protection.
- kernel
- The privileged core of an operating system, running in a special CPU mode with unrestricted access to memory and devices; it contains the scheduler, memory manager, filesystems, drivers, and security machinery.
- user space
- The unprivileged world where all ordinary programs run, confined to their own memory and required to request every hardware service from the kernel through system calls.
- system call
- The controlled doorway through which a user-space program asks the kernel for a service such as opening a file, allocating memory, or sending a network packet.
- file descriptor
- The small integer the kernel returns when a program opens a file — a ticket the program hands back on every subsequent read or write, while the kernel keeps the real bookkeeping.
- device driver
- A hardware-specific module, usually loaded into the kernel, that translates one device's particular dialect into the standard interface the rest of the system expects.
- filesystem
- The OS subsystem that organizes raw disk blocks into named files, folders, timestamps, and permissions — the human-usable fiction layered over storage hardware.
- permission
- A rule attached to a file or resource stating which users may read, write, or execute it; the kernel checks permissions during system calls, producing "Permission denied" on failure.
- virtual memory
- The memory-management scheme that gives each process a private, contiguous-looking address space mapped by page tables onto physical RAM, with less-used pages evicted to disk when memory runs short.
- process
- A program in execution: the running instance of a program file, with its own virtual address space, identity, and entry in the scheduler's ledger.
- shell
- The user-space program (such as zsh or bash) that reads typed commands and asks the kernel to run them — distinct from both the terminal window and the operating system itself.
- Unix
- The operating system begun at Bell Labs in 1969 by Ken Thompson and Dennis Ritchie, whose portable C implementation and licensed source code made its design the ancestor or model for macOS, Linux, and most server systems.
- Linux distribution
- A complete product (Ubuntu, Debian, Fedora, Arch) that packages the Linux kernel with installers, a package manager, default tools, and an update policy.
- WSL
- The Windows Subsystem for Linux — a Windows feature whose current version runs a real Linux kernel in a lightweight virtual machine, giving Windows users a genuine Linux environment alongside Windows.
- container
- A kernel-enforced isolated compartment of user space — separate process list, filesystem view, and network stack — that shares the host's kernel, packaged with an application's exact environment so it runs identically anywhere.
Sources and further reading
- Operating system — Wikipedia (accessed 2026-07-12)
- Kernel (operating system) — Wikipedia (accessed 2026-07-12)
- Operating Systems: Three Easy Pieces — Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau (accessed 2026-07-12) — Free, complete university-level OS textbook — the recommended deep dive after this lesson.
- History of Unix — Wikipedia (accessed 2026-07-12)
- Crash Course Computer Science — PBS Digital Studios (accessed 2026-07-12) — Free video series; the operating-systems episode complements this lesson.
Kept in this browser, no account needed. Your progress page turns the whole record into one link you can bookmark or open on another device.