Processes & Threads
Process lifecycle, process control block, thread models, context switching, inter-process communication (pipes, shared memory, message passing), and multi-threading.
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.
At its core, an OS has four primary responsibilities:
Additionally, the OS provides:
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 │ ││ └───────┘ └────────┘ └──────┘ └───────────┘ │└─────────────────────────────────────────────────────┘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:
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.
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:
syscall on x86-64, svc on ARM) triggers a trap that switches to kernel mode| Category | Examples | Purpose |
|---|---|---|
| Process Control | fork(), exec(), exit(), wait() | Create, run, and manage processes |
| File Management | open(), read(), write(), close() | Access and manipulate files |
| Device Management | ioctl(), read(), write() | Communicate with hardware devices |
| Information | getpid(), time(), uname() | Query system and process info |
| Communication | pipe(), socket(), send(), recv() | Inter-process and network communication |
| Memory | mmap(), brk(), sbrk() | Allocate and manage memory |
| Type | Description | Examples |
|---|---|---|
| Monolithic Kernel | All OS services run in kernel space in a single binary. Fast but a bug in any component can crash the whole system. | Linux, FreeBSD |
| Microkernel | Only 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 Kernel | Combines monolithic and microkernel approaches. Core services in kernel with some modularity. | Windows NT, macOS (XNU) |
| Exokernel | Minimal kernel that gives applications near-direct access to hardware. Maximizes performance and flexibility. | MIT Exokernel (research) |
| Type | Description | Examples |
|---|---|---|
| General-Purpose | Designed for a wide variety of tasks | Windows, macOS, Linux |
| Real-Time (RTOS) | Guarantees response within strict time deadlines. Used in safety-critical systems. | FreeRTOS, VxWorks, QNX |
| Embedded | Designed for resource-constrained devices with specific functions | Zephyr, Contiki, Embedded Linux |
| Distributed | Manages a group of networked computers, presenting them as a single system | Plan 9, Amoeba |
| Mobile | Optimized for smartphones and tablets with touch interfaces and power management | Android, iOS |
| Concept | Description |
|---|---|
| Process | A running instance of a program with its own address space |
| Thread | A lightweight unit of execution within a process |
| Context Switch | Saving one process’s state and loading another’s so the CPU can multitask |
| Virtual Memory | Abstraction that gives each process the illusion of having its own contiguous memory |
| Paging | Dividing memory into fixed-size blocks (pages) for efficient management |
| Deadlock | A state where two or more processes are stuck waiting for each other indefinitely |
| Semaphore | A synchronization primitive used to control access to shared resources |
| Interrupt | A signal from hardware or software that causes the CPU to pause and handle an event |
| Scheduling | The algorithm the OS uses to decide which process runs on the CPU next |
Processes & Threads
Process lifecycle, process control block, thread models, context switching, inter-process communication (pipes, shared memory, message passing), and multi-threading.
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.
Memory Management
Memory hierarchy, paging, segmentation, virtual memory, demand paging, TLB, page replacement algorithms (FIFO, LRU, Optimal, Clock), and thrashing.
Deadlocks & Synchronization
Critical section problem, mutexes, semaphores, monitors, deadlock conditions, resource allocation graphs, Banker’s algorithm, and classic synchronization problems.
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.
Week 3: CPU Scheduling
Understand how the OS decides which process runs next. Master the classic scheduling algorithms and practice Gantt chart problems.
Week 4: Memory & Synchronization
Dive into virtual memory, paging, and page replacement. Then tackle synchronization primitives and deadlock handling.