Operating Systems Cheatsheet
Overview
Use this Operating Systems reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
What is an Operating System?
An operating system (OS) is system software that manages hardware resources and provides services to application programs. It acts as an intermediary between users/applications and the computer hardware. OS knowledge explains why code slows down, crashes, blocks on I/O, runs safely in separate processes, and behaves differently under load.
An OS provides an environment in which programs can run. It is both a resource allocator (decides how to allocate resources efficiently and fairly) and a control program (controls execution of programs to prevent errors and misuse).
Core OS Roles
| Role | Description | Example |
|---|---|---|
| Resource Manager | Allocates CPU, memory, I/O | Scheduler assigns CPU time |
| Abstract Machine | Hides hardware complexity | read() hides disk geometry |
| Protection Boundary | Isolates processes from each other | Virtual address spaces |
| Interface Provider | Exposes system calls to programs | POSIX API |
| Daemon Supervisor | Manages background services | sshd, cron, systemd |
Kernel vs User Space
┌──────────────────────────────────────┐ │ User Space (unprivileged) │ │ Applications, shells, libraries │ ├──────────────────────────────────────┤ │ System Call Interface │ ├──────────────────────────────────────┤ │ Kernel Space (privileged) │ │ Process mgmt · Memory · FS · I/O │ ├──────────────────────────────────────┤ │ Hardware Abstraction Layer (HAL) │ ├──────────────────────────────────────┤ │ Physical Hardware │ └──────────────────────────────────────┘
Kernel mode (ring 0 on x86): full CPU instruction access, direct hardware control. User mode (ring 3 on x86): restricted; crossing to kernel requires a system call trap.
OS Architectures
| Architecture | Description | Examples | Pros / Cons |
|---|---|---|---|
| Monolithic | All OS services in one kernel binary | Linux, FreeBSD | Fast; large attack surface |
| Microkernel | Minimal kernel; services as user processes | Minix, QNX, Mach | Fault-isolated; IPC overhead |
| Hybrid | Monolithic with some isolation | Windows NT, macOS XNU | Balance of perf + modularity |
| Exokernel | Exposes raw hardware; library OSes handle abstractions | MIT Exokernel | Max flexibility; complex |
| Unikernel | App + OS compiled together, no user/kernel split | MirageOS | Tiny footprint; no isolation |
System Boot Sequence (x86/UEFI)
- Power-on → CPU fetches reset vector
- UEFI/BIOS firmware initializes hardware (POST)
- Boot loader (GRUB/bootmgr) loaded from EFI partition
- Boot loader loads kernel image + initial ramdisk (
initrd) - Kernel unpacks, initializes subsystems, mounts real root FS
- PID 1 launched (
systemd/init) - System services started; login prompt presented
Privilege Levels (x86 Rings)
| Ring | Name | Used By | Can Access |
|---|---|---|---|
| 0 | Kernel | OS kernel | All instructions, all memory |
| 1–2 | (unused in modern OSes) | — | — |
| 3 | User | Applications | Unprivileged instructions only |
Interrupt-Driven OS Design
- Hardware interrupt: external device signals CPU (keyboard, NIC, timer)
- Software interrupt / trap: deliberate (
int 0x80,syscall) - Exception: CPU detects error (divide by zero, page fault)
Device → IRQ line → PIC/APIC → CPU interrupt pin
CPU: save state → disable interrupts → jump to ISR
ISR: handle event → re-enable → IRET (restore state)Key Data Structures Maintained by the OS
| Structure | Purpose |
|---|---|
| Process Control Block (PCB) | Per-process state (PID, registers, page table ptr, …) |
| Ready Queue | Processes waiting for CPU |
| Device Queue | Processes waiting on I/O |
| Open File Table | Per-process + global file descriptors |
| Page Table | Virtual → physical address mapping |
| Interrupt Descriptor Table (IDT) | Maps interrupt vectors to handler routines |
OS Services Summary
- Program execution — load, run, terminate programs
- I/O operations — abstract device access
- File-system manipulation — create, delete, read, write files/directories
- Communications — pipes, sockets, shared memory
- Error detection — hardware faults, arithmetic errors, process errors
- Resource allocation — CPU cycles, memory, I/O bandwidth
- Accounting — track resource usage per user/process
- Protection & security — access control, authentication