Skip to content
BIASED

What an operating system does

Abstractions, resources, isolation; U/S/M and limited direct execution; monolithic/micro/hybrid; Linux as a distribution; the boot chain.

Three jobs of an OS

An operating system turns bare hardware into a place where many programs can run usefully and safely. Count three jobs. Abstractions give processes, virtual address spaces, files and sockets so application code never programs a NIC register or walks a page table by hand. Resource management multiplexes scarce CPU time, memory and device bandwidth among those abstractions. Isolation keeps processes out of each other’s memory and out of the kernel’s, so a bug becomes a crash or a denied syscall rather than silent corruption of another tenant.

The architecture half of the course — ISA, traps, caches, virtual memory — is the mechanism. The OS half is the policy and the software that uses those mechanisms every time you type a command.

Modes and limited direct execution

RISC-V privilege modes stack as U (user), S (supervisor/kernel), M (machine/firmware). Control enters the kernel only through a trap — ecall for syscalls, exceptions for faults, interrupts for devices and timers — to a vector the kernel programmed. Return uses sret (or mret from M). That design is limited direct execution: user code runs on the real CPU at native speed; the $U$ bit on page-table entries and the privilege level stop it from executing privileged instructions (SIGILL) or touching kernel pages (SIGSEGV) or talking to devices directly.

Without limited direct execution you would emulate every instruction (safe, slow) or trust every program (fast, fatal). The system-calls topic measures what each crossing costs; the processes topic shows what state the kernel saves when it switches between programs.

Structure and boot

Monolithic kernels (Linux) run file systems, networking and drivers in S-mode: short paths, shared address space for services, one fault domain — a wild pointer in a driver can panic the host. Microkernels (seL4, QNX) push servers into user processes and message between them: a crashed file server need not take down the scheduler, but a disk read may pay 8 boundary crossings instead of 2. Hybrids (Windows NT, XNU) keep critical paths in-kernel and leave others out.

What users call “Linux” is usually a distribution: kernel plus libc, coreutils, shell, init system and packages. The shell is not special — it is PID of some value, calling fork/exec like any other process. Boot climbs modes: ROM → firmware in M-mode → kernel in S-mode → init as PID 1 in U-mode, which then spawns the world. Next — C for systems programming, the language of that kernel and libc.

This topic’s checks ask for concrete numbers from the prose — page-sized PIPE_BUF and mode 0640 as 416, syscall number 64, microkernel crossings 8, busy fraction 20% — so that the abstractions stay pinned to the machine.

System calls, page faults and interrupts are three faces of the same entry mechanism. A blocking read puts the process in a wait queue and runs something else; the disk interrupt later wakes it. A timer interrupt forces a scheduling decision even when the process did not volunteer. Understanding an OS bug often means asking which entry path ran and which lock or wait queue it touched.

Virtual memory and files are twin abstractions: both map names (addresses, paths) to storage (frames, blocks) with caching (TLB/page cache) and permission checks. Sockets extend the file abstraction across machines. The rest of the systems half of the course is specialisation of these three jobs — abstractions, resources, isolation — under increasing concurrency and distribution.

Worked habit: for every new abstraction, write down (1) the kernel object, (2) the creating syscall, (3) what is shared after fork, (4) how EOF or termination is signalled, and (5) one concrete number (size, timeout, default limit). That checklist turns this course’s vocabulary into a debugging script you can run under strace.

Historical names still appear in docs: supervisor mode, ring 0, kernelspace versus userspace. They all name the same cut the RISC-V U/S/M stack makes precise. Dual-mode operation is older than Unix; what changed is the richness of the abstractions above the cut — copy-on-write fork, asynchronous I/O, namespaces — not the need for the cut itself. When you next boot a VM, watch how firmware hands off to a kernel that then creates PID 1: that handoff is the modes topic in chronological order.

Re-read the block markers as a study plan: each block’s checks are capped so that finishing the prose and the questions in one sitting stays realistic for Pulse. If a number in a check surprises you, jump back to the sentence that introduced it rather than memorizing in isolation.

Policy versus mechanism remains the organizing question when reading kernel source: wait queues and page-table bits are mechanisms; CFS weights and OOM killer heuristics are policies. Changing policy without understanding mechanism produces folklore tuning; learning mechanism without policy leaves you unable to choose. This course’s remaining topics alternate between the two on purpose.

Check your understanding

The same questions as in Pulse. Answers are shared between modes.

Full notes

Answers are saved on the server and tied to this browser until you sign in.