CSE Roadmap

Core tier · about 3 hours · 7 parts

Part 6 of 7 · 2 min read

Separate worlds

Why processes do not disturb each other

In plain words: Two processes can print the same address for a variable and still hold different values. Every process sees its own address space: a private numbering of memory that starts at zero and is mapped by the kernel to real memory. Address 0x404030 in one process and address 0x404030 in another point to different places in physical memory. The hardware does the translation. Level 6 explains how.

This is how the operating system keeps its promise from page 1 of Level 0, that each program seems to own the machine. It also explains why a crashed process rarely harms another one: a wild write goes into the process's own address space, and the address spaces of the others are out of reach.

Address space

An address space is the range of memory addresses that a process can reference, together with the mapping, kept by the kernel and the hardware, from those addresses to physical memory. Each process has its own, so the same address in two processes can refer to different data.

Example: two copies of the same program can both store a variable at address 0x404030, and each copy sees only its own value there.

Interview angle

Answer in your head first, then open it.

How does a program differ from a process?

A program sits on disk as a file of instructions. A process is a copy of it that is running and owns memory, registers and open files.

What are the sections of a process's memory?

Text, data, BSS, heap and stack.

Where do local variables, globals and malloc memory live?

Stack, data or BSS, and heap.

Which way does the stack grow?

Toward lower addresses on the common processors.

Check yourself: 1. Can two processes use the same address for different data? 2. Who translates a process's addresses to real memory? 3. Why can a crash in one process leave the others running?

Words you will meet

Word Meaning
Program A file with instructions, not running
Process A program in execution
Text The instructions of the program
Data, BSS Global variables with and without starting values
Heap Memory requested with malloc
Stack, stack frame Memory for calls; the part used by one call
Address space The addresses a process may use

Quick notes

  • A process is an instance of a program in execution: the executable code loaded into memory, its current state (program counter and registers), its own address space of text, data.
  • The stack is the region of a process's memory that holds one frame for each active function call (its arguments, local variables and saved return address); a frame is pushed when the function is called and popped when it returns.
  • An address space is the range of memory addresses that a process can reference, together with the mapping, kept by the kernel and the hardware, from those addresses to physical memory.