What is a process, and how can one program run twice?
A program is a recipe sitting on a shelf. A process is a cook actually working from it, and you can have several cooks on one recipe.
▶ Start the storyA process is a program that is actually running. A program is a passive collection of instructions, usually a file sitting on a disk. A process is what you get when those instructions are loaded into memory and executed. That is why you can run one program twice: open several of the same program and you often get more than one process, each its own cook working from the same recipe.
Program
- A passive file of instructions on disk
- Becomes a process when loaded and run
Process
- Executing instructions loaded into memory
- Owns resources: memory, open files
- Contains one or more threads
The operating system keeps track of every process in a record called a process control block, and it keeps processes separate, giving each the resources it needs so they are less likely to interfere with each other.
Why did anyone need the idea? In the early days, a program that waited for a slow device, such as a printer, left the processor idle, and computer time was neither cheap nor fully used. So the operating system learned to halt a waiting program and switch the processor to another one. Once programs could be paused and swapped like that, the notion of a program was expanded to an executing program and its context, and the concept of a process was born.
Inside a process there can be several threads. A thread is the smallest sequence of instructions the operating system's can manage on its own. A process owns the resources, such as memory and open files, while its threads are the workers that actually run. The catch is that threads share their process's memory, so one misbehaving thread can crash all the others.
Quiz me
0/3
Recap
A program is the recipe, a process is the cooking, and threads are the cooks sharing one kitchen.
💡 A trick to remember it · Recipe, kitchen, cooks: the program is the recipe, the process is the kitchen, the threads are the cooks who share it.
Surprising fact · Opening a program several times often creates several separate processes.
Sources (2)
No source, no claim. Every fact in this lesson (16 claims) cites at least one of these.