Course map

Topic 004 / Core

Operating system fundamentals

Chapter 1.2 · The Operating System and the Machine

What and why

Every program from topic 1 runs on top of something: the operating system is the layer that turns one physical machine into a safe, shared environment for many programs at once. It gives each program the illusion of owning the whole machine — its own memory, its own timeline of execution, files that just work — while actually multiplexing one set of physical resources among all of them. Builds on: → 1 (programs).

Diagram

OS responsibility What it gives a program Covered in depth
Process isolation its own address space, can't corrupt others → 5
Scheduling a fair share of CPU time → 6
Virtual memory the illusion of large, contiguous memory → 8
File system durable, named storage → 9
Networking sockets to talk to other machines Part 3

How it works

  1. The CPU enforces a privilege boundary: kernel space (trusted, full hardware access) and user space (restricted, your program) — hardware, not convention, stops a user program from touching another's memory.
  2. A system call is the only legal door from user space into a kernel service — opening a file, sending a packet, creating a process all cross through one.
  3. The scheduler time-slices the CPU across processes and threads, so one core can serve far more runnable tasks than it has cores (→ 6 formalizes this).
  4. The OS maintains virtual memory per process, translating virtual addresses to physical RAM so programs never see each other's real memory layout (→ 8).
  5. The OS mediates every I/O device; it decides when a program's read/write call actually touches disk or network versus being served from a cache it keeps on the program's behalf.

Practical example

Tracing a single read() call on an already-open file: the program calls read() → the CPU traps into kernel mode → the kernel checks the file descriptor is valid and the process has permission → the kernel copies bytes from its page cache (or, on a cache miss, issues the device read first) → the kernel copies those bytes into the program's buffer → control returns to user space. Every step after the trap is invisible to the program; it only sees a function call that returned some bytes.

When to use it

The judgment here is when to stop treating the OS as a black box:

  • Use this layer when debugging something a framework can't explain — unexpected memory growth, a process that won't start more threads, a file write that didn't survive a crash.
  • Avoid reasoning about OS internals for ordinary application logic — most code never needs to think below the language runtime.
  • Failure scenarios: assuming a file write is durable the instant the call returns (it may still be sitting in a cache the OS hasn't flushed to disk — the reason durability needs its own mechanism, → 68); assuming memory is free just because it was allocated — the OS can still run out and kill the process.
  • Simpler alternative: for most design decisions, a correct mental model — "the OS gives me processes, memory, and files, each with a cost" — is enough; drop to syscall-level tracing only when something concrete is unexplained.

Practice

(mechanism — trace by hand; 15–20 min, no lab services). Run a syscall tracer (e.g., strace on Linux, dtruss/dtrace on macOS, or your language's equivalent) on a program that opens a file, reads it, and closes it. List the syscalls made, in order, and name the kernel service each one invoked. Done when you can map every syscall in the trace to one row of the diagram above.

Key takeaway

The OS turns one machine into a safe, shared environment by mediating every process's access to CPU, memory, files, and the network. Done when you can: trace a simple file read down to its syscalls and name which OS responsibility each syscall exercises. Used next in → 5 (processes and threads), → 8 (memory management), → 9 (CPU, RAM, storage and I/O).

References

None — this topic makes no external claims.

Source directory

Search the guide