Lesson 10: What Happens When You Run a Program: Process, Memory & the OS
We've reached the last lesson, and the moment where it all connects. We built an executable — but what exactly happens when you click to run it? The OS loader creates a process: a running instance of the program, with its own private memory space. We'll see a process's memory layout — the code segme
When you run a program, the OS creates a 'process' for it — a live copy in memory with its own space. It has a stack for function calls and a heap for space requested on the fly. When the program wants to talk to the hardware, it asks the OS to do it.
- Process
- A running instance of a program, with its own private address space and state, managed by the OS.
- Loader
- Part of the OS that copies an executable into memory and creates a process from it.
- Address Space
- The range of memory addresses a process sees as its own; each process gets a private range thanks to virtual memory.
- Text & Data Segment
- The code segment holds the instructions (usually read-only); the data segment holds global variables and constants.
- Stack
- A memory region of function-call frames — local variables and return addresses; grows downward.
- Heap
- A memory region for dynamic allocation at runtime (malloc/new); grows upward as needed.
- Stack Frame
- The record pushed onto the stack on each function call: its local variables and the return address.
- System Call
- A request a program makes to the OS to perform an action requiring hardware access, such as output or input.
- Virtual Memory
- A mechanism in which each process gets a private address space, as if all memory were its own, mapped to physical memory.
- Context Switch
- Saving the running process's state and loading another's, so one CPU can serve many processes.