In this post, I will try to answer what is the difference between a program and a process.
In fact, this is a “subtle” question since the two terms sometimes are mistakenly used to refer to the same concept.
In addition, this is one of the “classic” question you could be asked for by an interviewer when you apply for a position as a software engineer.
To put it simply, a program is an executable file which resides on the secondary, persistent memory (i.e., disk), and only contains the set of instructions needed to accomplish a specific job. For instance, the
ls program is an executable file stored at
/bin/ls on the disk of a system running a Unix-like operating system.
Conversely, a process is a particular executing instance of a program when loaded to main memory, i.e., the actual execution of those instructions collected within the program. For instance, you might have multiple running instances of the
ls program above, thus multiple processes for the same program. It turns out that a program can be considered as a “static/passive” entity whereas a process is a “dynamic/active” entity.
In general, a process consists of the following resources:
– Memory, which includes an image of the executable code, process-specific data (input and output), a call stack (to keep track of active subroutines and/or other events), and a heap to hold intermediate computation data generated during run time. For further details on this, please refer to the post about the typical In-Memory Layout of a Program (Process).
– Operating system descriptors of resources that are allocated to the process, such as file descriptors (Unix terminology) or handles (Windows).
– Security attributes, such as the process owner and the process’ set of permissions.
– Processor state (i.e., context), such as the content of registers, physical memory addressing, etc. The state is typically stored in computer registers when the process is executing, and in main memory otherwise.
The operating system holds most of this information about active processes in data structures called Process Control Blocks (PCBs).