The relationship between a program and processes in the Operating System

operating systemsprocessprogram

A program, I am referring to any program written in any programming language. It could be a Java program which has only one method to do the multiplication, and a main method executes that multiplication method. Or it could be a program in Python does the same thing. Or it could be an application program such as an email client, a web browser, or a chat application, or an online game client.

Not sure if the main question makes any sense, but I am trying to figure out:

Is it correct to say each one of above is a program or there are some essential differences?

When I start a program, am I starting a process in the operating system?

Can a program have multiple processes?

Best Answer

Although there is no single source of truth about these terms, I think we can agree about the fundamental difference between a program and a process:

  • a program is a set of instructions intended to achieve a goal. It is an artifact.

    • Instructions may be expressed in a human readable high level language or an equivalent low level (compiled) machine instructions bundled in an executable.
    • The question is about boundaries: is each file of instructions a separate program ? or are all the files together considered as a program ? I'd naively think that the program has a notion of being self contained: it is made of all the instruction files needed to allow an independent execution.
  • an OS process is the execution of a program: so it's not only a set of instructions, but also a flow of execution of the program's instruction, together with an execution context (stack, values of variables, resources, etc...):

    • a program can be written with instructions for using multiple threads . It's still one program executed by one process.
    • a program can load and run another program within the same process. So a process can execute several programs, but at any given moment in times it's only one active.
    • however several process may be required to work together (wheteher if all these processes execute/fork the same program or not). Several processes/programs working together, are a system.
    • special case for interpreted languages : the OS process(es) will run the interpreter (or the abstract machine), which wil in turn execute the program.

Some references

C++ ISO standard:

§3.5: A program consists of one or more translation units linked together.

§2.1 The text of the program is kept in units called source files (...). A source file together with all the headers and source files included (...) is called a translation unit

§1.9 Program execution [nothing is said about processes, the implementation is free to organize execution as bes suits the purpose]

Java 8 language specifications:

Chapter 1.1:

Chapter 12 describes activities that occur during execution of a program. A program is normally stored as binary files representing compiled classes and interfaces. These binary files can be loaded into a Java Virtual Machine, linked toother classes and interfaces, and initialized.

POSIX specifications:

3.300 Program: A prepared sequence of instructions to the system to accomplish a defined task. The term "program" in IEEE Std 1003.1-2001 encompasses applications written in the Shell Command Language, complex utility input languages (...), and high-level languages.

3.289 Process: An address space with one or more threads executing within that address space, and the required system resources for those threads.

Related Topic