How Programs Run

A program is a set of instructions written by a person, but the CPU introduced in the first topic can only execute machine code — raw instructions encoded as the bits described in the data-representation topic — so every program must somehow cross the gap from human-written text to those executable bits before the fetch-decode-execute cycle can run it. Source code is the program in the form a person actually writes: text in a programming language such as Python, C, or JavaScript, saved in an ordinary file of the kind the working-with-a-computer topic described, readable and editable by humans but meaningless to the CPU on its own. A compiler is a tool that translates an entire source file ahead of time into a separate machine-code file the processor can run directly, which is why compiled languages like C produce a standalone executable that starts quickly but must be rebuilt after every change. An interpreter instead reads the source code and carries out its instructions line by line while the program runs, with no separate machine-code file produced, which is why interpreted languages like Python can run a script immediately without a build step but generally execute more slowly, since the translation happens over and over as the program runs. Many modern languages blend the two approaches: Java and C# first compile source into a portable intermediate form called bytecode, which a runtime then executes — often using just-in-time compilation to turn the hottest bytecode into machine code on the fly — so the same compiled file can run on any machine that has the runtime. Once a program is actually running, the operating system — the master program the first topic named as the manager of the hardware — loads its instructions into the RAM covered earlier and represents the running program as a process: a live instance with its own slice of memory, its own open files, and its own place in the queue the OS uses to decide which process gets the CPU next. Because a computer runs many processes at once but a CPU core can only execute one instruction stream at a time, the operating system rapidly switches the core between processes — a maneuver called a context switch — fast enough that a browser, a music player, and an editor all appear to run simultaneously even on a single core. All of this rests on the same foundation the earlier topics built: instructions and data are just bits, the CPU blindly executes whatever machine code it is given, and the entire job of compilers, interpreters, and the operating system is to turn the programs people write into exactly those bits and feed them to the processor in an orderly way.

Source code
human-written text in a language like Python or C
Compiler
translates the whole file ahead of time into a machine-code executable
Interpreter
reads and runs the source line by line, no separate file
Bytecode + JIT
compiles to a portable intermediate form, then to machine code as it runs
Machine code
raw instructions encoded as bits the CPU can execute
The OS loads it as a process
its own memory, files, and turn on the CPU; the OS context-switches between many
Two Paths From Source Code to a Running CPU compiled ahead of time vs. interpreted line by line Source code human-written text Compiled (e.g. C) compiler translates the whole file once, ahead of time produces a standalone executable starts fast, rebuilt after each change Interpreted (e.g. Python) interpreter reads and runs the source line by line as it goes no separate file, runs immediately translation repeats, so often slower CPU executes machine code (bits)
Many Processes, One Core, Rapid Switching the OS gives each process a short turn, then context-switches to the next Browser process own memory + open files Music player process own memory + open files Editor process own memory + open files Operating system scheduler picks which process runs next One CPU core runs one instruction stream at a time

Take how programs run further

Ask the copilot about this term, or have our engineers assess it against your process.