OS Foundations and Process Model

Lesson, slides, and applied problem sets.

View Slides

Lesson

OS Foundations and Process Model

Why this module exists

Operating systems are the boundary between hardware and programs. Most bugs in systems code are not about syntax; they are about state, privilege, and invariants. This module builds the mental model for processes, system calls, and lifecycle edges that every later subsystem depends on.


1) Privilege and the syscall boundary

User code cannot directly touch hardware or kernel memory. The OS provides system calls that cross a privilege boundary:

  • User mode: restricted instructions, no direct device access.
  • Kernel mode: full access, handles traps/interrupts.

A syscall is a controlled entry into the kernel. This is where arguments are validated, permissions are checked, and resources are allocated.


2) Processes as state machines

A process is more than code; it is state:

  • address space (page tables)
  • registers (including program counter)
  • open files
  • scheduling metadata (priority, time slice)

Core states:

  • RUNNING: on CPU now
  • READY: runnable, waiting for CPU
  • BLOCKED: waiting on I/O or a synchronization event
  • ZOMBIE: exited, waiting to be reaped

Transitions are caused by syscalls, interrupts, or scheduling decisions.


3) Fork, exec, exit, wait

Classic Unix lifecycle:

  • fork() duplicates process state (logical copy).
  • exec() replaces the current address space with a new program.
  • exit() terminates the process.
  • wait() lets a parent collect exit status (reap zombies).

If a parent exits before a child, the child is reparented to init (PID 1). This avoids orphaned processes.


4) Context switch cost

Switching CPU from one process to another is not free:

  • save registers
  • load new page table
  • flush or invalidate TLB
  • pipeline and cache disruption

Schedulers trade fairness and latency against this cost.


5) What you will build

  • A process table that tracks parents, children, exits, and reaping.
  • Correct handling of zombies and reparenting.

Key takeaways

  • Processes are state machines with strict invariants.
  • The syscall boundary is about privilege and validation.
  • Fork/exec/exit/wait define most process lifecycle edges.
  • Reparenting and zombies are expected, not exceptional.

Module Items