{}DSA Atlas

OS Foundations

What an operating system does, user mode vs kernel mode, system calls, interrupts and traps, the boot process and kernel architectures (monolithic, microkernel, hybrid).

Beginner6 interview questions

What an operating system does

An operating system is the software layer between applications and hardware. It has two jobs:

  1. Abstraction — turn messy hardware into clean, uniform concepts: CPUs become threads, RAM becomes a private address space, disks become files, network cards become sockets.
  2. Resource management and protection — share the hardware among many programs fairly and safely: decide who runs on the CPU, who gets memory, and stop programs from interfering with each other.
Applications (browser, database, your server) user mode · ring 3 System libraries (libc, runtime) — wrap system calls system call boundary Kernel · kernel mode · ring 0 Scheduler Memoryvirtual memory File systems+ network stack Device drivers Hardware: CPU · RAM · disk · NIC · timer
The kernel sits between applications and hardware. Crossing the dashed line costs a mode switch.

Dual-mode operation

The CPU itself enforces protection with a mode bit:

User modeKernel mode
Privileged instructions (I/O, change page tables, disable interrupts)✗ trap✓
Memory accessibleonly the process's mapped pageseverything
Who runs hereapplications, librarieskernel, (in monolithic kernels) drivers
A crash meansthat process diesthe whole machine panics

On x86 these are protection rings (0 = kernel, 3 = user; 1–2 unused by mainstream OSes). Virtualization adds a further level below ring 0 for the hypervisor.

System calls

A system call is the controlled entry point from user mode into the kernel. The program places the syscall number and arguments in registers and executes a trap instruction; the CPU switches to kernel mode and jumps to a fixed handler.

#include <unistd.h>
#include <fcntl.h>

int main(void) {
    int fd = open("notes.txt", O_RDONLY);     // syscall: open
    char buf[128];
    ssize_t n = read(fd, buf, sizeof buf);     // syscall: read (may block)
    write(STDOUT_FILENO, buf, n);              // syscall: write
    close(fd);                                 // syscall: close
    return 0;
}
import os

fd = os.open("notes.txt", os.O_RDONLY)   # thin wrappers over the same syscalls
data = os.read(fd, 128)
os.write(1, data)
os.close(fd)

Run strace ./prog (Linux) or dtruss (macOS) to see every syscall a program makes — a great debugging and interview-story tool.

Categories of system calls

CategoryExamples (POSIX/Linux)
Process controlfork, execve, exit, wait, kill
File managementopen, read, write, close, lseek, stat
Device managementioctl, read/write on device files
Informationgetpid, clock_gettime, uname
Communicationpipe, socket, send, recv, mmap, shmget
Protectionchmod, chown, setuid, seccomp

Interrupts, exceptions and traps

EventSynchronous?CauseExample
Hardware interruptno (async)device signals the CPUtimer tick, packet arrived, disk done
Exception / faultyesthe current instructionpage fault, divide by zero, illegal instruction
Trap / syscallyesdeliberate requestsyscall instruction

The timer interrupt is the foundation of multitasking: it fires periodically (or on demand in tickless kernels), returning control to the kernel so the scheduler can preempt a process that would otherwise never give up the CPU.

Interrupt handling is split into a fast top half (acknowledge the device, grab data, run with interrupts disabled briefly) and a deferred bottom half (softirqs, tasklets, workqueues) that does the heavier processing.

The boot process

  1. Firmware (UEFI) runs POST and initialises hardware.
  2. Loads the bootloader from the EFI system partition.
  3. Bootloader loads the kernel and initramfs, passes the kernel command line.
  4. Kernel initialises subsystems, mounts root, starts PID 1 (systemd).
  5. PID 1 starts services and the login manager.

Kernel architectures

ArchitectureIdeaExamplesProsCons
Monolithiceverything in kernel spaceLinux, FreeBSDfast (function calls)one bug can crash everything
Microkernelminimal kernel; drivers/FS as user-space serversseL4, QNX, MINIX 3isolation, verifiabilityIPC overhead
Hybridmicrokernel structure, services in kernel spaceWindows NT, macOS XNUbalancecomplexity
Unikernelapp + library OS compiled into one imageMirageOS, Unikrafttiny, fast bootsingle app, harder debugging

Virtualization and containers (the modern context)

  • A hypervisor runs multiple OSes on one machine. Type 1 runs on bare metal (KVM, Xen, Hyper-V, ESXi); Type 2 runs on a host OS (VirtualBox). Hardware support (Intel VT-x, AMD-V, nested page tables) makes it fast.
  • A container is not a VM: processes on the same kernel, isolated with namespaces (pid, net, mount, uts, ipc, user, cgroup — what a process can see) and limited with cgroups (CPU, memory, I/O — what it can use). Containers start in milliseconds and share the kernel, so isolation is weaker than VMs (hence gVisor, Firecracker microVMs, Kata).

Interview questions

0 / 6 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.