Operating systems · Fundamentals
Introduction to operating systems
Kernel, syscalls, and the hardware contract
Start here
If you have never studied OSes before, read the definition and first-time map below first. They introduce words (kernel, syscall, privilege) that every later section reuses. You do not need assembly or C yet, only patience with layered explanations.
What is an operating system? (formal picture)
An operating system (OS) is a layer of trusted software that sits between application programs and the physical machine. Its job is to multiplex limited hardware (one or a few CPUs, finite RAM, shared disks and devices) so that many programs appear to run at once, while enforcing rules: who may touch which memory, which files, and which devices.
The kernel is the privileged core of the OS: it runs in a CPU mode that can configure the memory management unit (MMU), handle interrupts, and schedule threads. User space is where normal applications run; they must request privileged work through a narrow, audited interface called system calls. That split-untrusted user code vs trusted kernel code: is the central design idea of this entire course.
Big picture for first-time learners
Program vs process
Kernel vs shell
Why virtual memory exists
Interrupts and concurrency
Dual-mode operation (theory)
When your code executes a trap instruction for a syscall, the CPU raises privilege, jumps to a kernel entry point, and runs handler code on a per-thread kernel stack. When the handler finishes, privilege is lowered and execution resumes in user space. A page fault is another trap: it may be benign (e.g. demand paging) or fatal (SIGSEGV).
Mechanism vs policy: the kernel provides mechanisms (runqueues, page tables, syscall tables). Policies (which process runs next, how much memory a cgroup may use) are configured by the same kernel but are conceptually separate, interviews often reward stating which side you mean.
Mental model to keep
By the end of this page you should be able to
- Explain why user programs cannot install new page tables directly.
- Name at least four resources the OS multiplexes (CPU, RAM, disk, devices, …).
- Trace a high-level path from a library call (e.g. `open`) to a syscall and back.
- Contrast mechanism with policy using one scheduling example.
Course summary (narrative)
Operating systems sit between bare metal and applications. They create the illusion of private memory and infinite CPUs by time-slicing and address translation, persist data through hierarchical file systems, and protect the machine with privilege levels and access checks. Production systems add cgroups, namespaces, and MAC, but all of that still rests on these fundamentals.
TL;DR
The OS is trusted firmware+software that multiplexes CPU, memory, and devices while enforcing isolation, user programs never touch privileged hardware directly, only through audited system calls.
Control flow across the boundary
Read the diagram definition
flowchart LR
U[User: libc + app] -->|syscall insn| K[Kernel: syscall entry]
K --> V[VFS / MM / sched]
V --> D[Drivers / IRQ]
D -->|wake| K
K -->|iret| UDeeper narrative
Treat the OS as a policy engine wrapped around hardware mechanisms: the same MMU hardware can implement swapping or hard caps; the same timer interrupt can drive CFS fairness or RT deadlines. Interviewers reward connecting textbook layers (trap → syscall dispatch → return path) to observability (`strace`, `perf`, `/proc`).
Syscall path as a story
User issues a capability
Libraries translate intent (`fopen`) into syscalls (`openat`) with validated pointers and flags.
Privileged transition
CPU raises privilege, kernel copies args, indexes syscall table, runs handler in process context.
Kernel cooperates with hardware
Handlers may sleep on wait queues; device interrupts complete I/O and wake waiters.
Return to user
Kernel packs errno + retval, restores user GPRs, lowers privilege; user code continues or handles errors.
Privilege ring sketch
USER KERNEL
ring 3 ring 0
| syscall / fault |
v-----------------^Takeaways
Dual-mode operation
Mechanism vs policy
Boot is part of the OS story
Observability wins interviews
Did you know?
Common pitfalls
Confusing APIs with mechanisms
`printf` buffering lives in libc; the actual console path may involve `write`, tty discipline, and driver DMA, trace before claiming “one syscall.”
Ignoring firmware/boot
Secure Boot, ACPI tables, and IOMMU setup precede your first line of kernel C but shape security and NUMA topology.
What the OS is responsible for (sample mapping)
What the OS is responsible for (non-exhaustive)
| Resource | Abstraction | Typical mechanism |
|---|---|---|
| CPU | Threads / processes | Scheduler + timer interrupts |
| RAM | Private virtual address spaces | Paging + page tables + TLB |
| Disk / SSD | Named files & durability | VFS + block I/O + FS journal |
| Devices | File descriptors / IOCTL | Drivers + interrupt/DMA path |
Glossary
Trap / exception
Mechanism vs policy
ABI
Interview follow-ups
- Name something that is not a syscall but still requires kernel cooperation.
- How does a hypervisor change the privilege story without changing user code?
- Where would you look to prove a performance regression crosses the user/kernel boundary?
Callouts
Interview framing
Start answers with the invariant being protected (e.g., “TLB entries must match current address space”), then name the mechanism enforcing it.
Hands-on
Run `man 2 intro` on Linux for a categorized syscall list, then `strace -c true` to see how even trivial programs cross the boundary.
Walkthrough
60-second elevator pitch
Trace one syscall
Deep dive
Traps, faults, and interrupts
Monolithic vs microkernel (tradeoffs)
Why virtual machines reappear in “OS” courses
See syscalls in flight
strace -e trace=process,memory,file -o /tmp/trace.log your_binarywc -l /tmp/trace.log
Self-check
1Which action requires kernel mode on a typical Unix?
2A device interrupt handler usually runs in…
3The stable interface applications rely on across kernel versions is primarily…
4Which component typically runs first after power-on on a PC-class system?