Last Minute Notes

OS Fundamentals

Beginner operating system concepts: what an OS does, kernel vs user space, CPU privilege modes, system calls, interrupts and exceptions, kernel architectures (monolithic, microkernel, hybrid), the boot process, virtualization and containers at a glance, and the Linux, Windows, and macOS landscape.

📘 OS Fundamentals

This page is the foundation for the whole Operating Systems section. It explains what an operating system is for, how the CPU keeps applications from breaking each other, and how a program asks the kernel for help.

Table of Contents

  1. What an Operating System Does
  2. Kernel Space and User Space
  3. System Calls
  4. Interrupts, Exceptions, and Traps
  5. Kernel Architectures
  6. The Boot Process
  7. Types of Operating Systems
  8. Virtualization and Containers
  9. The OS Landscape
  10. Beginner Questions

1. What an Operating System Does

An operating system sits between hardware and applications. It has two jobs:

  1. Resource manager: share CPU time, memory, disks, and devices among many programs fairly and safely.
  2. Abstraction provider: give programs simple interfaces (processes, files, sockets) instead of raw hardware.
AbstractionHidesCovered in
ProcessA CPU shared with hundreds of other programsProcesses and Threads
ThreadMultiple cores and interleaved executionProcesses and Threads
Virtual memoryLimited, fragmented physical RAMMemory Management
FileDisk blocks, SSD pages, device detailsFile Systems and Storage
SocketNetwork cards and protocolsI/O and Linux Internals
File descriptor"Everything is a file" handle for all of the above on UnixI/O and Linux Internals

Goals that pull against each other: efficiency (use hardware well), fairness, isolation and security, responsiveness, and simplicity for programmers.


2. Kernel Space and User Space

The kernel is the core of the OS that runs with full hardware privilege. Everything else runs in user space with restricted privilege.

The CPU enforces this with privilege modes:

ArchitectureMost privilegedLeast privileged
x86-64Ring 0 (kernel)Ring 3 (user); rings 1 and 2 unused
ARM64EL1 (kernel), EL2 (hypervisor), EL3 (firmware)EL0 (user)
RISC-VM-mode (machine), S-mode (supervisor)U-mode (user)

In user mode, the CPU refuses privileged instructions (disable interrupts, change page tables, talk to devices directly). Trying one causes a fault, and the kernel usually kills the process.

Why the split matters:

  • A buggy application cannot crash the machine or read another process's memory.
  • The kernel can enforce permissions (who can open which file).
  • Crossing the boundary costs time, so high-performance systems try to cross it less often (batching, io_uring, kernel bypass like DPDK).

3. System Calls

A system call is how a user program asks the kernel to do something privileged.

CategoryLinux examples
Process controlfork, execve, exit, wait4, clone, kill
File managementopen, read, write, close, lseek, stat, fsync
Device managementioctl, mmap
Informationgetpid, uname, clock_gettime
Communicationpipe, socket, connect, sendmsg, shmget, mmap
Memorybrk, mmap, munmap, mprotect
Protectionchmod, setuid, seccomp

Facts to remember:

  • A system call costs roughly 100 ns to a few microseconds, much more than a function call, and more since Spectre and Meltdown mitigations.
  • Some calls avoid the switch: Linux maps a small shared library called the vDSO into every process so clock_gettime and gettimeofday run in user space.
  • strace -c ./program counts system calls; it is the fastest way to see what a program is really doing.
  • Library call vs system call: printf is a library function that buffers and eventually calls write.

4. Interrupts, Exceptions, and Traps

Control reaches the kernel in three ways.

EventSourceTimingExample
Hardware interruptDeviceAsynchronousNIC received a packet, disk finished, timer tick
Exception (fault)The current instructionSynchronous, unintentionalPage fault, divide by zero, invalid opcode
TrapThe current instructionSynchronous, intentionalsyscall instruction, breakpoint (int3)

The CPU looks up a handler in the interrupt vector table (IDT on x86), saves the current state, and switches to kernel mode.

Linux splits interrupt handling in two:

  • Top half (the hard IRQ handler): runs immediately with interrupts disabled, does the minimum (acknowledge the device, grab the data).
  • Bottom half (softirqs, tasklets, workqueues): does the rest later with interrupts enabled.

The timer interrupt is what makes preemptive multitasking possible: even a program stuck in while (true) {} gets interrupted so the scheduler can run someone else.

Polling vs interrupts: at very high packet rates, interrupts per packet overwhelm the CPU, so network drivers switch to polling (Linux NAPI) under load.

DMA (direct memory access) lets devices copy data to RAM without the CPU; the CPU only gets an interrupt when the transfer is done.


5. Kernel Architectures

ArchitectureIdeaProsConsExamples
MonolithicAll services (drivers, FS, network) in kernel spaceFast (function calls, no IPC)One bad driver crashes everything, large attack surfaceLinux, BSDs
MicrokernelKernel does only IPC, scheduling, basic memory; the rest are user-space serversIsolation, reliability, verifiableIPC overheadseL4, QNX, MINIX 3, Fuchsia (Zircon)
HybridMicrokernel structure, but many services run in kernel space for speedBalanceComplexityWindows NT, macOS XNU (Mach + BSD)
Exokernel / unikernelMinimal kernel, app links its own OS libraryTiny, fast bootSingle app, nicheMirageOS, Unikraft

Linux is monolithic but modular: drivers load at runtime as kernel modules (lsmod, modprobe). It also gains microkernel-like safety through eBPF, which lets verified programs run inside the kernel safely, and Rust is now accepted for new drivers.


6. The Boot Process

StageDetail
FirmwareUEFI replaced BIOS; runs self-tests, finds a boot device, reads the EFI system partition (GPT disks)
Secure BootFirmware only runs bootloaders and kernels signed by trusted keys
BootloaderLoads the kernel image and the initramfs (a small temporary root file system with drivers needed to mount the real root)
KernelSets up page tables, scheduler, drivers, mounts the root FS, starts PID 1
init / systemdStarts services in parallel based on dependencies; PID 1 also adopts orphaned processes

7. Types of Operating Systems

TypeGoalExample
BatchRun queued jobs without interactionEarly mainframes, HPC job schedulers (Slurm)
MultiprogrammingKeep the CPU busy by switching when a job waits for I/OThe idea behind every modern OS
Time-sharing / multitaskingRapid switching so many users feel they own the machineUnix, all desktop OSes
Real-time (RTOS)Guaranteed deadlinesFreeRTOS, Zephyr, QNX, VxWorks; Linux has PREEMPT_RT merged since 6.12
DistributedMany machines appear as oneResearch systems; Kubernetes is the practical cousin
EmbeddedSmall, fixed-function devicesRouters, appliances, cars
MobileBattery, touch, sandboxed appsAndroid (Linux kernel), iOS (XNU)

Hard real-time: missing a deadline is a failure (airbag, pacemaker). Soft real-time: missing a deadline degrades quality (video playback, audio).


8. Virtualization and Containers

Virtual machineContainer
Isolation boundaryHypervisor, separate kernel per VMShared host kernel, isolated with namespaces and cgroups
StartupSeconds to minutesMilliseconds to seconds
OverheadHigher (full guest OS)Near native
Security isolationStrongWeaker (kernel bugs are shared); hardened by seccomp, user namespaces, gVisor, Kata
Image sizeGBsMBs
ExampleKVM, VMware, Hyper-V, Xen, Firecracker microVMsDocker, containerd, Podman

Hypervisor types:

  • Type 1 (bare metal): runs directly on hardware (KVM, which turns Linux into a hypervisor, ESXi, Hyper-V, Xen); clouds use these.
  • Type 2 (hosted): runs on a host OS (VirtualBox, VMware Workstation, Parallels).

Hardware support (Intel VT-x, AMD-V, ARM virtualization extensions) and nested page tables (EPT, NPT) made virtualization nearly native speed.

Firecracker microVMs (behind AWS Lambda and Fargate) combine VM-grade isolation with container-like startup of about 125 ms.

Containers are covered in depth in I/O and Linux Internals.


9. The OS Landscape

OSKernelNotes
LinuxMonolithic, modularRuns almost all servers, clouds, Android, supercomputers; distributions: Ubuntu, Debian, RHEL, Fedora, Alpine, Amazon Linux
WindowsHybrid (NT)Desktops, enterprise, gaming; WSL2 runs a real Linux kernel in a lightweight VM
macOS / iOSHybrid (XNU: Mach + BSD)Apple silicon (ARM64), APFS file system
FreeBSD / OpenBSDMonolithicNetflix CDN, networking appliances, security focus
AndroidLinux kernel + ART runtimeMost smartphones

POSIX is the standard API (processes, files, signals, threads) that Unix-like systems share, which is why the same C code compiles on Linux and macOS.


10. Beginner Questions

QuestionShort answer
What is an operating system?Software that manages hardware resources and provides abstractions like processes, files, and sockets
What is a kernel?The privileged core of the OS that runs in kernel mode
Kernel mode vs user mode?Full hardware access vs restricted; enforced by the CPU
What is a system call?A controlled entry into the kernel to request a privileged service
Interrupt vs exception vs trap?Async from a device vs sync error from an instruction vs sync intentional (syscall)
Monolithic vs microkernel?All services in the kernel for speed vs minimal kernel with user-space servers for isolation
What happens when you power on a computer?Firmware, bootloader, kernel, init, services
VM vs container?Separate kernel per VM vs shared kernel with namespaces and cgroups
What is preemptive multitasking?The timer interrupt lets the OS take the CPU away from a running task
What is POSIX?The standard Unix API so programs are portable

Next: Processes and Threads.

On this page