Skip to content

Operating Systems

An operating system (OS) is the most important software that runs on a computer. It manages the computer’s hardware resources — CPU, memory, storage, and I/O devices — and provides a stable, consistent interface for application programs to use. Without an operating system, every program would need to handle hardware directly, making software development impossibly complex.

Whether you are writing a web server, a mobile app, or a machine learning pipeline, the OS is silently orchestrating everything underneath. Understanding how it works will make you a significantly better engineer.

What Does an Operating System Do?

At its core, an OS has four primary responsibilities:

  1. Process Management — Creating, scheduling, and terminating processes and threads
  2. Memory Management — Allocating and deallocating memory, implementing virtual memory
  3. File System Management — Organizing data on storage devices, managing file access and permissions
  4. I/O Management — Handling communication between the CPU and peripheral devices (disk, network, keyboard, display)

Additionally, the OS provides:

  • Security and access control — Protecting processes from each other and enforcing user permissions
  • Networking — Managing network connections and protocols
  • User interface — Providing a command-line or graphical interface for human interaction

Kernel vs User Space

The most fundamental architectural concept in operating systems is the separation between kernel space and user space. This boundary is enforced by the CPU hardware itself.

┌─────────────────────────────────────────────────────┐
│ USER SPACE │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ Web │ │ Text │ │ Database │ │
│ │ Browser │ │ Editor │ │ Server │ │
│ └────┬─────┘ └────┬─────┘ └──────┬───────┘ │
│ │ │ │ │
│ ──────┴─────────────┴───────────────┴────────── │
│ System Call Interface │
│ (open, read, write, fork, │
│ exec, mmap, socket...) │
│ ─────────────────────────────────────────────── │
│ │
├─────────────────────────────────────────────────────┤
│ KERNEL SPACE │
│ │
│ ┌────────────────────────────────────────────┐ │
│ │ Kernel │ │
│ │ │ │
│ │ ┌───────────┐ ┌──────────┐ ┌────────┐ │ │
│ │ │ Process │ │ Memory │ │ File │ │ │
│ │ │ Scheduler │ │ Manager │ │ System │ │ │
│ │ └───────────┘ └──────────┘ └────────┘ │ │
│ │ │ │
│ │ ┌───────────┐ ┌──────────┐ ┌────────┐ │ │
│ │ │ Device │ │ Network │ │ Security│ │ │
│ │ │ Drivers │ │ Stack │ │ Module │ │ │
│ │ └───────────┘ └──────────┘ └────────┘ │ │
│ └────────────────────────────────────────────┘ │
│ │
├─────────────────────────────────────────────────────┤
│ HARDWARE │
│ │
│ ┌───────┐ ┌────────┐ ┌──────┐ ┌───────────┐ │
│ │ CPU │ │ Memory │ │ Disk │ │ Network │ │
│ │ │ │ (RAM) │ │ │ │ Interface │ │
│ └───────┘ └────────┘ └──────┘ └───────────┘ │
└─────────────────────────────────────────────────────┘

Kernel Space

The kernel is the core of the operating system. It runs with full hardware privileges (Ring 0 on x86 processors) and has unrestricted access to all hardware and memory. The kernel is responsible for:

  • Managing the CPU scheduler and deciding which process runs next
  • Handling interrupts from hardware devices
  • Managing physical and virtual memory
  • Providing the file system implementation
  • Enforcing security boundaries between processes

User Space

User space is where all application programs run. Programs in user space have restricted access — they cannot directly touch hardware or access another process’s memory. When a user-space program needs to perform a privileged operation (reading a file, sending a network packet, allocating memory), it must ask the kernel through a system call.

Why the Separation Matters

  • Stability — A bug in a user program cannot crash the entire system
  • Security — One program cannot read or modify another program’s data
  • Fairness — The kernel ensures all programs get their share of resources

System Calls

A system call is the mechanism by which a user-space program requests a service from the kernel. It is the only legal way for applications to interact with hardware resources.

When a program invokes a system call:

  1. The program places the system call number and arguments in CPU registers
  2. A special CPU instruction (e.g., syscall on x86-64, svc on ARM) triggers a trap that switches to kernel mode
  3. The kernel validates the request and performs the operation
  4. Control returns to the user program with the result

Common Categories of System Calls

CategoryExamplesPurpose
Process Controlfork(), exec(), exit(), wait()Create, run, and manage processes
File Managementopen(), read(), write(), close()Access and manipulate files
Device Managementioctl(), read(), write()Communicate with hardware devices
Informationgetpid(), time(), uname()Query system and process info
Communicationpipe(), socket(), send(), recv()Inter-process and network communication
Memorymmap(), brk(), sbrk()Allocate and manage memory

Types of Operating Systems

By Kernel Architecture

TypeDescriptionExamples
Monolithic KernelAll OS services run in kernel space in a single binary. Fast but a bug in any component can crash the whole system.Linux, FreeBSD
MicrokernelOnly essential services (IPC, basic scheduling, memory) in kernel. Other services run in user space. More stable but slower due to extra context switches.Minix, QNX, seL4
Hybrid KernelCombines monolithic and microkernel approaches. Core services in kernel with some modularity.Windows NT, macOS (XNU)
ExokernelMinimal kernel that gives applications near-direct access to hardware. Maximizes performance and flexibility.MIT Exokernel (research)

By Purpose

TypeDescriptionExamples
General-PurposeDesigned for a wide variety of tasksWindows, macOS, Linux
Real-Time (RTOS)Guarantees response within strict time deadlines. Used in safety-critical systems.FreeRTOS, VxWorks, QNX
EmbeddedDesigned for resource-constrained devices with specific functionsZephyr, Contiki, Embedded Linux
DistributedManages a group of networked computers, presenting them as a single systemPlan 9, Amoeba
MobileOptimized for smartphones and tablets with touch interfaces and power managementAndroid, iOS

Key Concepts at a Glance

ConceptDescription
ProcessA running instance of a program with its own address space
ThreadA lightweight unit of execution within a process
Context SwitchSaving one process’s state and loading another’s so the CPU can multitask
Virtual MemoryAbstraction that gives each process the illusion of having its own contiguous memory
PagingDividing memory into fixed-size blocks (pages) for efficient management
DeadlockA state where two or more processes are stuck waiting for each other indefinitely
SemaphoreA synchronization primitive used to control access to shared resources
InterruptA signal from hardware or software that causes the CPU to pause and handle an event
SchedulingThe algorithm the OS uses to decide which process runs on the CPU next

Topics Covered

Processes & Threads

Process lifecycle, process control block, thread models, context switching, inter-process communication (pipes, shared memory, message passing), and multi-threading.

Explore Processes & Threads →

CPU Scheduling

Scheduling criteria and algorithms: FCFS, SJF, SRTF, Round Robin, Priority Scheduling, Multilevel Queue, and MLFQ. Includes Gantt charts, comparison tables, and practice problems.

Explore CPU Scheduling →

Memory Management

Memory hierarchy, paging, segmentation, virtual memory, demand paging, TLB, page replacement algorithms (FIFO, LRU, Optimal, Clock), and thrashing.

Explore Memory Management →

Deadlocks & Synchronization

Critical section problem, mutexes, semaphores, monitors, deadlock conditions, resource allocation graphs, Banker’s algorithm, and classic synchronization problems.

Explore Deadlocks & Synchronization →


Week 1: Fundamentals

Start here. Understand what an OS does, kernel vs user space, and system calls. This page covers everything you need to begin.

Week 2: Processes & Threads

Learn how programs are executed, how processes are created with fork/exec, and how threads enable concurrency within a single process.

Begin Processes & Threads →

Week 3: CPU Scheduling

Understand how the OS decides which process runs next. Master the classic scheduling algorithms and practice Gantt chart problems.

Begin CPU Scheduling →

Week 4: Memory & Synchronization

Dive into virtual memory, paging, and page replacement. Then tackle synchronization primitives and deadlock handling.

Begin Memory Management →


Ready to Begin?