Processes & Process Control

a process versus a program

A common beginner mix-up is to use 'program' and 'process' as if they meant the same thing. They do not. A program is like sheet music: a static file sitting on disk, the same bytes every time you look at it, doing nothing on its own. A process is the orchestra playing that music right now: a dynamic, living performance that has a beginning, occupies the hall, uses up time and energy, and eventually ends. The same sheet music can be performed many times, by many orchestras, at once.

Precisely: a program is the executable file - the compiled instructions and initial data stored on disk, plus the rules for how to lay it out in memory. A process is one running instance of that program: a private address space the kernel created from the program, a CPU register state, a set of open files, a PID, and an entry in the kernel's process table. The program is the noun on the shelf; the process is the verb in action. Running the same program twice creates two distinct processes with different PIDs and different memory, even though they read their instructions from the very same file.

Why this matters: nearly every confusing question in this field clears up once you hold the difference. 'How many copies of Chrome are running?' is a question about processes, not the one Chrome program file. fork() makes a new process, not a new program. When a program ends we say the process terminated, the file is untouched. Mixing the two leads to sentences that sound fine but are nonsense, like 'the program is using 40% of the CPU' - it is a process that uses CPU, because only a running thing can use anything.

ls is a program: one file at /bin/ls. Every time you type ls in a shell, the OS creates a brand-new process from that file, it runs for a few milliseconds, prints names, and the process exits. The file /bin/ls never changed; many short-lived processes came and went.

One unchanging program file gives rise to many separate, short-lived processes.

Loose speech blurs them ('run the program'), and that is fine in casual talk. But when reasoning about resources, scheduling, PIDs, or fork/exec, force yourself to say which one you mean - a file, or a running instance.

Also called
program vs process靜態程式 vs 動態行程