Part 2 of 7 · 1 min read
Program versus process
Think of it this way. A recipe in a cookbook does nothing by itself. A cook who follows it, with a stove, ingredients and a place in the recipe, makes a meal. The recipe is the program and the cook at work is the process. The analogy stops at one point: one recipe can be followed by many cooks at once, and each cook has a separate kitchen.
In plain words: A program is a passive file on disk that holds instructions and data. It uses no processor time. When the operating system loads that file into memory and starts it, the result is a process. A process is active. It has a next instruction to run, values in registers, memory and open files.
Two processes can come from the same program. Open a text editor twice and there are two processes. Their code is identical, but each has its own variables, its own place in the code and its own files. One process cannot read the other's memory.
Process
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, heap and stack, and the kernel resources assigned to it, such as open files. A program is a passive file, and a process is the active entity made from it.
Example: typing ls in a shell turns the program file /bin/ls into a process that lives for a fraction of a second.
Check yourself:
1. Is a file named a.out on disk a program or a process?
2. If two users run the same editor, how many processes exist?
3. Name one thing that two such processes do not share.