The Complete Guide to How Computers Work for Systems Programmers
A bottom-up tour of how a computer runs your code: bits, memory, the CPU, caches, interrupts, DMA, virtual memory and the kernel, with C programs and output.

Most programmers work a few layers above the machine, and that is fine until something goes wrong in a way the layers hide. A program is slow although the algorithm is right. A value changes when nothing wrote to it. A struct is bigger than its fields add up to. A server stalls under load with the CPU nearly idle. Every one of those has an answer below the language, in how the hardware stores bits, how the processor executes instructions and how the operating system shares both among programs.
This guide builds that picture from the bottom, in the order a program meets it: bits and numbers, memory and addresses, the processor and its instruction cycle, the clock, the memory hierarchy, storage, interrupts and DMA, the operating system's view of memory and privilege, and finally the path from a source file to a process. Each section has a C program that shows the idea, and its output is worked out from the code. The examples assume Linux on x86-64 with GCC 14 and glibc 2.40, and they say so whenever a result depends on the platform. The guide is the hub for this part of the site, so each section names the deeper post on its topic.
If you only want the short version, here it is. A computer is a processor that repeatedly fetches an instruction from memory, decodes it and executes it, changing registers and memory. Everything else, from caches to virtual memory to the kernel, exists to make that loop fast, safe and shareable.
The machine in one picture
Take a laptop apart on paper and you find four kinds of parts that matter to a program.
The processor, or CPU, executes instructions. Modern chips contain several cores, each of which is a complete processor that can run its own stream of instructions.
Main memory, RAM, holds the instructions and data of every running program. The CPU reads and writes it by address.
Storage such as an SSD keeps data when the power is off. It is much larger and much slower than RAM.
Devices are everything else: the network card, the display controller, the keyboard, the USB ports and the timer. A device is controlled by reading and writing its registers, and it asks for attention with an interrupt.
These parts are joined by buses, sets of wires that carry addresses, data and control signals. On current hardware the buses are fast serial links such as PCIe and the memory channels, and the logical picture is unchanged: the CPU issues a read or write to an address, and something answers, either memory or a device.
A fifth part is not hardware at all, and it matters as much: the operating system. The kernel runs on the same CPU as your program, but in a privileged mode, and it decides which program runs when, which memory each can touch and who may use each device. A program talks to the machine only through the kernel, which is why a guide to the machine must include it.
The rest of this guide takes these parts one at a time, starting with the smallest thing they all share.
Bits, bytes and numbers
The machine stores everything as bits, each a 0 or a 1. Hardware groups bits into bytes of 8, and nearly every modern system addresses memory in bytes: an address names one byte, and larger values occupy consecutive addresses. A word is the natural width for the processor's registers and arithmetic: 64 bits on current desktop and phone chips, 32 on many microcontrollers. The post on word size covers what 32-bit and 64-bit change in detail, and the key consequence is that pointers are as wide as the word.
Integers
An unsigned integer of n bits stores values from 0 to 2ⁿ − 1 in plain binary. A signed integer uses two's complement: the top bit has weight −2ⁿ⁻¹ instead of +2ⁿ⁻¹. That makes the range −2ⁿ⁻¹ to 2ⁿ⁻¹ − 1 and, more important, makes addition the same operation for signed and unsigned values, so the processor needs one adder. The negation of a value is its bitwise complement plus one, and −1 is all ones.
#include <stdint.h>
#include <stdio.h>
int main(void) {
int8_t values[] = { 0, 1, 127, -1, -128 };
for (int i = 0; i < 5; i++)
printf("%4d = 0x%02X\n", values[i], (unsigned)(uint8_t)values[i]);
uint8_t u = 255;
u = (uint8_t)(u + 1);
printf("255 + 1 as uint8_t = %u\n", u);
return 0;
}gcc -std=c17 -Wall -Wextra twos.c -o twos
./twos 0 = 0x00
1 = 0x01
127 = 0x7F
-1 = 0xFF
-128 = 0x80
255 + 1 as uint8_t = 0The same byte 0xFF is 255 if you read it as unsigned and −1 if you read it as signed. The hardware does not know which you mean: you choose by the type, and the processor reports through its flags whether an operation overflowed in either reading. Unsigned arithmetic in C wraps around by definition, as the last line shows. Signed overflow is undefined behavior in C, so the compiler may assume it never happens, which is a frequent source of surprises when code relies on it wrapping.
Byte order
A value wider than a byte occupies several consecutive addresses, and there are two ways to order its bytes. Little-endian stores the least significant byte at the lowest address, and big-endian stores the most significant byte first. x86-64 and most Arm systems running Linux are little-endian, and network protocols use big-endian, which is why they are called "network byte order".
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint32_t x = 0x01020304;
const unsigned char *p = (const unsigned char *)&x;
printf("bytes in memory:");
for (int i = 0; i < 4; i++)
printf(" %02x", p[i]);
putchar('\n');
return 0;
}bytes in memory: 04 03 02 01Looking at the bytes through an unsigned char pointer is allowed by the C standard and is the portable way to inspect an object's representation. The result is 04 03 02 01 on a little-endian machine. Byte order matters whenever bytes cross a boundary: reading a file written on another machine, parsing a network packet, or reading a device register. Inside a program, with ordinary typed access, you never see it.
Text and other data
Characters are numbers with an agreed table. ASCII uses 7 bits for the English alphabet, digits and punctuation, and UTF-8 encodes the full Unicode set in one to four bytes per character, keeping ASCII bytes unchanged. Floating-point numbers follow IEEE 754: a sign bit, an exponent and a fraction, so that values are approximations with a fixed relative precision. Instructions are numbers too, which is the idea at the center of the next sections: code and data are both just bytes in memory.
Memory and addresses
Memory is a long array of bytes, and an address is an index into it. A pointer is a variable that holds an address. On a 64-bit system it is 8 bytes, which is why a pointer-heavy structure costs so much more than the data it points to, as the post on data structure memory costs measures.
Alignment and padding
The hardware reads memory most efficiently in aligned chunks: a 4-byte integer should start at an address divisible by 4, and an 8-byte one at an address divisible by 8. Some processors fault on a misaligned access, and others handle it slowly. To keep every member aligned, the compiler inserts padding. The rule is that each member goes at the next offset that is a multiple of its alignment, and the whole struct is padded to a multiple of its largest member's alignment so that arrays of the struct stay aligned.
#include <stddef.h>
#include <stdio.h>
struct Wasteful { char a; int b; char c; };
struct Packed { int b; char a; char c; };
int main(void) {
printf("Wasteful: a@%zu b@%zu c@%zu size=%zu\n",
offsetof(struct Wasteful, a), offsetof(struct Wasteful, b),
offsetof(struct Wasteful, c), sizeof(struct Wasteful));
printf("Packed: b@%zu a@%zu c@%zu size=%zu\n",
offsetof(struct Packed, b), offsetof(struct Packed, a),
offsetof(struct Packed, c), sizeof(struct Packed));
return 0;
}Wasteful: a@0 b@4 c@8 size=12
Packed: b@0 a@4 c@5 size=8Both structs hold the same six bytes of data. In the first, three bytes of padding follow a so that b lands on offset 4, and three more follow c so the total is a multiple of 4, which gives 12. Putting the largest member first removes the interior padding and the struct shrinks to 8. This is also the answer to "why is my struct larger than its fields": the difference is padding. It matters most in arrays of millions of structs.
The process's view of memory
A running program sees memory in regions. The code (the .text section) holds machine instructions and is mapped read-only and executable. Read-only data holds string literals and constants. Static data holds global and static variables, initialized (.data) or zero-filled (.bss). The heap grows as malloc requests memory. Each thread has a stack that holds function frames: return addresses, arguments, local variables and saved registers. Printing one address from each shows the layout:
#include <stdio.h>
#include <stdlib.h>
int global_counter = 7;
int main(void) {
int local = 1;
void *heap = malloc(16);
printf("code (main): %p\n", (void *)main);
printf("data (global): %p\n", (void *)&global_counter);
printf("heap (malloc): %p\n", heap);
printf("stack (local): %p\n", (void *)&local);
free(heap);
return 0;
}code (main): 0x55d1c3a0a149
data (global): 0x55d1c3a0d010
heap (malloc): 0x55d1c4e2d2a0
stack (local): 0x7ffd3a6c1b9cThe exact numbers differ on every run, because the kernel randomizes where it places each region, a defense called address space layout randomization. What stays constant is the ordering: the program image at the low end, the heap just above it, and the stack far above, near the top of the user address range. Those are virtual addresses, a point the section on virtual memory picks up.
The processor
The CPU is built from three kinds of part, covered in depth in the post on registers, the ALU and the control unit. Registers are a few dozen fast storage cells inside the core, each as wide as the word. The arithmetic logic unit computes results and condition flags from register values. The control unit reads each instruction and routes data accordingly. Everything the processor does is a movement of data between registers, memory and the ALU.
Some registers have special jobs. The program counter holds the address of the next instruction, called rip on x86-64. The stack pointer, rsp, holds the address of the top of the current stack. The flags register records whether the last operation produced zero, a negative result, a carry or an overflow, and conditional jumps read it. When you write if (a < b), the compiler emits a subtraction or comparison that sets flags, followed by a jump that tests them.
Instructions
An instruction is a small number that tells the control unit what to do. It has an opcode that selects the operation and operands that name registers, constants or memory locations. The complete set of instructions a processor understands, together with its registers and the way it addresses memory, is its instruction set architecture, covered in its own post. x86-64, AArch64 and RISC-V are three ISAs, and a compiled program is tied to one.
You can see what the compiler produces for a simple function. With gcc -O2 -S on x86-64, this C:
int add(int a, int b) {
return a + b;
}compiles to two instructions:
leal (%rdi,%rsi), %eax
retThe calling convention puts the two arguments in rdi and rsi and the result in eax. The lea instruction computes the sum of the two registers into eax in one step, and ret pops the return address from the stack into the program counter. Two instructions, and no memory access: the whole function runs inside the core.
The fetch-decode-execute cycle
The processor runs one loop forever. It fetches the instruction at the address in the program counter and advances the counter. It decodes the instruction to find the operation and operands. It executes the operation, which changes a register, memory or the program counter itself. Then it repeats.
A jump or call is nothing more than an instruction that writes a new value into the program counter. A function return reads a saved address off the stack and writes it into the counter. An interrupt, which later sections cover, is an event that makes the processor save the counter and load a different one. Once you see the loop, control flow stops being mysterious.
The post on building a tiny CPU emulator in C writes this loop in about eighty lines, with four registers and six instructions, and its trace shows pc taking the values 06, 08, 0a and then 06 again as a loop runs. The structure of a real processor is far more complex, with pipelines and out-of-order execution that overlap many instructions, but the visible behavior, one instruction after another in program order, is preserved by contract.
The clock
Digital circuits run on a clock, a signal that ticks at a fixed rate. On each tick, storage cells capture the values that logic settled on during the previous interval. The time between ticks is a clock cycle, and the rate is the clock speed: 3 GHz means three billion cycles per second, so one cycle takes a third of a nanosecond.
The post on clock cycles works the arithmetic. The main lesson here is what clock speed does not tell you. Work done per second is the number of instructions executed, times the cycles each one needs, divided by the clock rate: time = instructions × cycles per instruction × period. Two chips at the same frequency can differ by a large factor in instructions per cycle, because a wide core can finish several independent instructions in the same cycle and a simple one finishes at most one. A processor waiting for memory completes none, however fast the clock. Frequency also costs power, which is why chips stopped getting faster clocks around the mid-2000s and became wider and more parallel instead.
For code, the practical consequences are two. Cycle counts of instructions are properties of a specific chip, found in its manual or measured, never assumed. And a program that stalls on memory is not helped by a faster core, only by touching memory more kindly, which is the subject of the next section.
The memory hierarchy
A processor can do arithmetic faster than memory can supply operands, by a wide margin. The gap is closed with layers of storage, each larger and slower than the one above: registers, then L1, L2 and L3 caches, then RAM, then storage. The post on the memory hierarchy explains each layer. The mechanism that makes it work is locality: programs tend to reuse data they just used (temporal locality) and to touch data near what they just touched (spatial locality).
Caches exploit locality by moving data in blocks called cache lines, 64 bytes on most current x86-64 and Arm processors. When you read one int, the hardware brings the whole 64-byte line containing it into the cache, so the next fifteen ints in the array are already there. The following program counts, for different strides through a 1,024-element array, how many reads occur and how many distinct cache lines they touch. It uses no timing, so its output is the same everywhere.
#include <stdio.h>
#define N 1024
#define LINE_BYTES 64
int main(void) {
for (int stride = 1; stride <= 32; stride *= 2) {
int reads = 0, lines = 0, last_line = -1;
for (int i = 0; i < N; i += stride) {
int line = (int)(i * sizeof(int)) / LINE_BYTES;
if (line != last_line) {
lines++;
last_line = line;
}
reads++;
}
printf("stride %2d: %4d reads, %2d cache lines\n", stride, reads, lines);
}
return 0;
}stride 1: 1024 reads, 64 cache lines
stride 2: 512 reads, 64 cache lines
stride 4: 256 reads, 64 cache lines
stride 8: 128 reads, 64 cache lines
stride 16: 64 reads, 64 cache lines
stride 32: 32 reads, 32 cache linesReading every element touches 64 lines for 1,024 reads, sixteen useful reads per line. Reading every sixteenth element touches the same 64 lines for only 64 reads, so each line brought in serves a single read. The first pattern is cheap per element because the line fetch is shared. The second pays a full line fetch for every element. This is the mechanism behind two rules of thumb: walk arrays in address order, and prefer contiguous structures to ones joined by pointers, which scatter elements across lines.
Two further cache effects show up in real programs. False sharing happens when two cores write different variables that sit in the same cache line: the line bounces between their private caches, and both slow down although they share no data. Padding each variable to its own line fixes it. And cache coherence is the hardware protocol that keeps all cores' views of a line consistent, which is why shared-memory programming works without software cache management on mainstream processors, and why DMA-capable devices on cores with data caches need explicit cache maintenance, a point the DMA section returns to.
Memory that remembers and memory that forgets
Memory technologies split by whether they survive power loss. Volatile memory loses its contents: SRAM, used for caches and the working memory of microcontrollers, and DRAM, used for main memory, which stores each bit as charge on a capacitor that leaks and must be refreshed. Non-volatile memory keeps its contents: flash, which stores charge on an insulated gate and is what an SSD or a microcontroller's program memory is made of, EEPROM and ROM.
The post on volatile and non-volatile memory covers the write rules, and the one that surprises programmers is that flash can only change bits from 1 to 0 by writing. To get a 1 back, you must erase a whole sector, which sets every bit in it to 1. So programming a byte is effectively new = old & data, and rewriting needs an erase first. Flash also wears out after a limited number of erase cycles, listed in each part's datasheet.
On a PC this is hidden by an SSD controller that remaps and spreads writes. On a microcontroller it is yours to manage, and it explains why firmware keeps fast-changing values in RAM, writes settings to flash only when they change, and splits a program between flash for code and constants and RAM for variables and the stack.
C's volatile keyword has nothing to do with this. It tells the compiler that a variable can change without the program's own code touching it, such as a hardware register or a variable updated by an interrupt handler, so every access in the source must actually happen. It belongs in the next section.
Talking to devices
A device is controlled through registers, and most systems expose them in the same address space as memory. This is memory-mapped I/O: a store to a particular address is a command to the device, and a load from another is a status read. On a Cortex-M microcontroller, turning on a GPIO pin is a write to a fixed address:
#include <stdint.h>
#define GPIOA_ODR (*(volatile uint32_t *)0x40020014u)
void led_on(void) { GPIOA_ODR |= (1u << 5); }
void led_off(void) { GPIOA_ODR &= ~(1u << 5); }The address is the output data register of GPIO port A on an STM32F4 part. The volatile qualifier forces the compiler to perform each read and write exactly as written, since the register's value is meaningful, and not to cache it in a CPU register or drop a write that looks redundant. On a PC, user programs never touch device registers: the kernel does, in drivers, and exposes devices as files and system calls.
Interrupts
A device cannot wait for the CPU to ask whether it has something to report, and the CPU should not waste time asking. An interrupt reverses the arrangement: the device signals the processor, which stops the current code, saves the state needed to return, jumps through a vector table to a handler for that source, and resumes afterward when the handler returns. The post on interrupts explains the hardware sequence and the rules for handlers.
The practical rules are the ones every embedded programmer learns early. Keep the handler short, because other interrupts wait while it runs. Do not block or call functions that might. Clear the device's request flag, or the handler fires again immediately. Mark variables shared with the main code volatile, and make multi-word updates atomic. Do the heavy work later in the main loop, with the handler setting a flag or queuing a message. Linux calls the split a top half and a bottom half.
DMA
Copying data between a device and memory one word at a time with the CPU, called programmed I/O, keeps the processor busy for the whole transfer. Direct memory access hands the job to a dedicated engine. The CPU writes a source address, a destination address and a count into the DMA controller's registers and starts it. The engine moves the data on the bus, and an interrupt announces completion. The post on DMA models a channel in C and covers the two ways it fails: stale data from CPU caches that the engine bypasses, and passing a device a virtual address it cannot use. Linux's DMA mapping API, dma_map_single and friends, exists to handle both.
Privilege: why there is a kernel
If every program could execute every instruction and touch all memory, any bug or malicious program could corrupt the others, or the whole machine. Processors prevent this with at least two privilege modes. Kernel mode, ring 0 on x86, can run every instruction and access all memory and devices. User mode, ring 3, cannot execute privileged instructions such as halting the CPU or loading page tables, and can access only memory that the kernel has mapped for the process.
A user program that needs a service, such as reading a file, asks the kernel through a system call. On Linux x86-64 the program places the call number in rax and arguments in rdi, rsi, rdx, r10, r8 and r9, then executes the syscall instruction, which switches to kernel mode and jumps to one entry point the kernel set up at boot. The kernel validates the arguments, does the work and returns with the result in rax. The post on user mode, kernel mode and system calls shows a program that makes calls directly, and one that executes a privileged hlt and receives SIGSEGV.
The C library functions you call every day, such as fopen and printf, are user-mode code that eventually makes these system calls, usually after buffering to avoid the cost of crossing the boundary on every byte. That crossing is much more expensive than a function call, so reading a file a byte at a time with read is slow in a way that reading it in large blocks is not.
Virtual memory
The addresses a program uses are not the addresses of physical RAM. The processor contains a memory management unit that translates each virtual address to a physical address using page tables the kernel maintains. Memory is divided into pages, 4 KiB on most systems, and the translation maps virtual pages to physical frames. This one mechanism provides several things at once.
Isolation. Each process has its own page tables, so an address in one process names different memory than the same number in another, and a process cannot reach memory the kernel has not mapped for it.
Protection. Each page table entry carries permission bits: readable, writable, executable, and user or kernel only. A write to a read-only page, or a jump into a data page marked non-executable, raises a fault.
Flexibility. Pages need not be contiguous in physical memory, so the kernel can give a process a large contiguous virtual range from scattered frames. It can share the same physical page between processes, as it does for the code of a shared library, and it can leave pages unmapped until first use.
Overcommit and paging. The kernel can hand out more virtual memory than there is RAM, and can move rarely used pages to storage, bringing them back on demand.
How an address is translated
On x86-64 with four-level paging, a virtual address is 48 bits that the hardware splits into five fields. The low 12 bits are the offset within a 4 KiB page. The next four groups of 9 bits each index one level of a tree of tables, from the top (PML4) down to the last (the page table), and the last table's entry holds the physical frame number. The program below does the split for one address, using the stack address from the regions example.
#include <stdint.h>
#include <stdio.h>
int main(void) {
uint64_t va = 0x00007ffd3a6c1b9cULL;
printf("virtual address : 0x%016llx\n", (unsigned long long)va);
printf("PML4 index : %llu\n", (unsigned long long)((va >> 39) & 0x1ff));
printf("PDPT index : %llu\n", (unsigned long long)((va >> 30) & 0x1ff));
printf("PD index : %llu\n", (unsigned long long)((va >> 21) & 0x1ff));
printf("PT index : %llu\n", (unsigned long long)((va >> 12) & 0x1ff));
printf("page offset : 0x%llx\n", (unsigned long long)(va & 0xfff));
printf("virtual page no.: 0x%llx\n", (unsigned long long)(va >> 12));
return 0;
}virtual address : 0x00007ffd3a6c1b9c
PML4 index : 255
PDPT index : 500
PD index : 467
PT index : 193
page offset : 0xb9c
virtual page no.: 0x7ffd3a6c1The hardware walks four tables, using indexes 255, 500, 467 and 193, to find the physical frame, and then appends the offset 0xb9c. Doing four memory reads for every access would be ruinous, so the processor caches recent translations in the translation lookaside buffer, the TLB. A TLB hit costs almost nothing. A miss costs a table walk, and a context switch to a different process can invalidate entries unless the hardware tags them with an address-space identifier. The reach of the TLB is a reason large data sets benefit from huge pages, which map 2 MiB or more with a single entry.
Page faults
If the page table has no valid entry for an address, or the access violates its permissions, the processor raises a page fault and the kernel's handler runs. There are three outcomes. If the address is valid but not yet backed by memory, as with the first touch of freshly allocated memory, the kernel allocates a frame, zeroes it, maps it and resumes the program: a minor fault, invisible to the program except for the time. If the data must come from storage, as with a file mapping not yet in the page cache, it is a major fault and takes much longer. And if the access is illegal, the kernel delivers SIGSEGV, which is what a null pointer dereference does.
You can watch minor faults happen. mmap reserves address space without backing it. Touching one byte per page forces the kernel to supply frames, and getrusage counts the faults:
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <unistd.h>
static long minor_faults(void) {
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
return ru.ru_minflt;
}
int main(void) {
long page = sysconf(_SC_PAGESIZE);
size_t pages = 64;
unsigned char *p = mmap(NULL, pages * page, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (p == MAP_FAILED)
return 1;
long before = minor_faults();
for (size_t i = 0; i < pages; i++)
p[i * page] = 1; /* first touch of each page */
long after = minor_faults();
printf("page size: %ld bytes\n", page);
printf("faults for %zu first touches: %s\n", pages,
(after - before) >= (long)pages ? "at least 64" : "fewer than 64");
munmap(p, pages * page);
return 0;
}page size: 4096 bytes
faults for 64 first touches: at least 64The call to mmap returned instantly with no memory behind it, and each first write took a fault that the kernel resolved by mapping a zeroed frame. That is demand paging, and it is why a process can allocate a gigabyte and use almost none of it. It is also why the first pass over a new buffer is slower than the second, and why malloc returning non-null does not guarantee that the memory is there when you touch it.
Processes, threads and context switches
A process is a running program with its own address space and resources. A thread is a flow of control inside a process, with its own registers and stack and a shared address space. A computer with four cores runs many more threads than four by letting each have the CPU for a short while. The kernel's scheduler picks which thread runs, and a timer interrupt gives it the chance to take the CPU back, which is what makes multitasking preemptive.
Stopping one thread and starting another is a context switch. The processor state of the old thread, its registers, program counter, stack pointer and flags, is saved, and the new thread's state is loaded. If the new thread belongs to a different process, the page tables are switched too. On Linux x86-64, user registers are saved on the kernel stack when the thread enters the kernel, and the switch itself swaps kernel stacks and a handful of callee-saved registers. The post on context switches walks through it and counts switches with getrusage.
The direct cost of a switch is small. The indirect cost is the cold cache and TLB afterward, which is why a server with thousands of busy threads can spend more time switching than working, and why event-driven designs that serve many connections from one thread exist.
Concurrency and parallelism
These are different ideas. Concurrency is structuring a program as tasks whose lifetimes overlap, which works on one core by taking turns. Parallelism is running computations at the same instant on several cores. The post on concurrency versus parallelism shows both in C, with a cooperative loop for the first and four pthreads summing a range for the second, and states Amdahl's law: the speedup from n cores is at most 1 / ((1 − p) + p / n) for a parallel fraction p, so a program that is 90 percent parallel cannot go more than ten times faster however many cores you add.
Shared data is where concurrency becomes difficult, because two cores can read and write the same memory at once. A data race, two accesses with at least one write and no ordering between them, is undefined behavior in C11 and later. The tools for avoiding them are the topic of the concurrency posts: mutexes, atomic operations and message passing. The hardware side of the answer is the memory model, the rules for which writes other cores may observe in which order, which on x86 are strict and on Arm and RISC-V are weaker, so code that happens to work on one can fail on another.
From source file to running process
All of the above meets in the path a program takes from text to a running process, which the posts on object file formats and the exec path cover in depth.
Compile. The compiler turns each C file into an object file of machine code, plus symbol and relocation information. For a quick look, gcc -S shows the assembly it generates.
Link. The linker joins object files and libraries, resolves symbol references to addresses, and writes an executable in the platform's format: ELF on Linux, PE on Windows and Mach-O on macOS. The file contains headers that describe segments to map, the entry point and a list of shared libraries needed.
Load. When you run ./program, the shell forks a child, which calls execve. The kernel discards the child's memory, maps the executable's segments with the permissions in its headers, maps the dynamic loader named in the file, builds a stack with the arguments, environment and an auxiliary vector, and starts the loader. The loader maps the shared libraries, applies relocations and jumps to _start.
Run. _start calls the C library's initialization, which runs constructors and then calls main. When main returns, exit runs destructors, flushes buffers and makes the exit_group system call.
Putting the layers together, the line printf("hello\n") has a long route. The code of printf formats the text into a user-space buffer. When the buffer is flushed, at a newline on a terminal, the C library calls write. The syscall instruction moves the CPU to kernel mode. The kernel checks the file descriptor and the buffer pointer, finds the terminal driver and queues the bytes. The terminal emulator reads them and asks the display system to draw glyphs, which becomes commands to the graphics hardware, written to device registers. Each step crosses one of the boundaries in this guide: user to kernel, kernel to device, CPU to memory.
What this model leaves out
The picture here is the one every systems programmer needs first, and it is a simplification in several places.
Pipelines and out-of-order execution. Modern cores overlap the execution of dozens of instructions and run them out of order when their inputs are ready, then retire them in program order. The visible behavior matches the simple loop, but timing does not, and speculation about branches led to a family of security vulnerabilities disclosed in 2018 that kernel and compiler mitigations address.
Multiple cores and memory ordering. Each core has private caches kept coherent by hardware, and each may reorder its own memory operations as seen by others. Correct concurrent code must use atomic operations and fences, or locks that include them, rather than assuming operations become visible in source order.
Vector units and GPUs. Processors have wide registers that apply one operation to many values at once, and GPUs run thousands of simple threads. Both are reached through special instructions or separate programming models.
Virtualization. A hypervisor adds another layer below the kernel, with a second level of address translation. Containers, by contrast, are not virtual machines: they are ordinary processes with restricted views of kernel resources.
Other architectures. Microcontrollers often have no MMU, no cache and no privilege split, so the whole of their memory is one flat space, a task can overwrite another's stack, and the design discipline that the kernel enforces elsewhere falls to the programmer. Everything in the first half of this guide still applies, and most of the second half does not.
A path through the rest of the site
The posts linked above go deeper on each section, and a sensible order is the order of this guide. Start with the CPU parts and the emulator to see the instruction cycle written as code. Continue to the memory hierarchy, interrupts and DMA for the hardware side. Then read the user and kernel mode post, the context switch post and the exec path to understand the operating system's role. After that, the data structure guide in this series shows how the choices in this guide, contiguous memory against pointers and padding against packing, determine the real cost of every container.
When you meet a bug or a slow program you cannot explain, ask which layer owns the symptom. A value that changes by itself is probably a data race or a missing volatile. A result that differs between machines may be byte order, struct padding or word size. A slow loop is probably memory access, not arithmetic. A crash on first use of a pointer is a page fault the kernel could not satisfy. The model is only useful if you reach for it, and with practice the layer shows itself quickly.


