1

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?

  • Possible duplicate of How do programming languages integrate with OS runtimes – gnat Jul 25 '16 at 21:31
  • @gnat I found the context of my question and the one you referred are not the same. tbh, I kind get what that question is asking for but I kind have no idea what the answer to that question was talking about. – s-hunter Jul 25 '16 at 21:42
6

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.

  • Great explanations of program and process. Is it correct to say a process is created when a program is started no matter if the program consist of only one source file (a simple script) or consist of hundreds or thousands of source files(those big desktop apps)? – s-hunter Jul 25 '16 at 23:59
  • @s-hunter i'd say yes: you'd always start an execution process. However bear in mind that it's not necessarily an OS process (see special case of interpreted languages) – Christophe Jul 26 '16 at 6:39
2

To a simple definition, a program is really just a piece of data typically that lives on the disc as a file. That data, of course, contains both encodings of cpu instructions along with data (like string literals, etc..)

Whereas a process is a program loaded into memory and usually has been started. Loading a program into a process usually means allocating an address space, and otherwise creating context for the process, loading the code (encoded instructions) and other data into that address space, and giving the program cpu time starting with the main.

is it correct to say each one of above is a program or there are some essential difference among them?

Essentially, yes.

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

Yes.

Can a program have multiple processes?

It depends on the definitions applied, but programs these days can have multiple threads but not necessarily processes. However, it is not unusual for someone to refer to a group of programs as a single program. It could be said that such program has been divided into several processes (even though that also means the program has been split into multiple program (files).

  • Is a java class with only 50 lines and a email client application both a program can only have one process? – s-hunter Jul 25 '16 at 21:28
  • The notion of process offers a boundary of protection, so two programs would not typically share one process even if they are small, if I understand your question. – Erik Eidt Jul 25 '16 at 21:32
  • 1
    You would usually call Chrome one program, but each tab has its own process. – Sebastian Redl Jul 25 '16 at 21:57
  • @SebastianRedl, agreed. You get many processes with chrome! – Erik Eidt Jul 25 '16 at 22:07
1

What is the relationship between a program and processes in the Operating System?

Depends on the program.

I can write low level program that doesn't need an operating system. Indeed that's what an operating system is. If the hardware supports everything I need I won't even miss the os.

If however, I need to load a file and have no OS to help out I'm in for a bit of work. The OS normally abstracts things away that I'd normally rather not think about. What kind of controller does the drive have? What commands are used to address data? This isn't easy without an OS that dictates a common interface for drivers to implement so you can talk to every hard drive controller the same way.

As for math, well now were talking to the ALU, maybe. Maybe the CPU does this natively on this hardware. More stuff you have to know because the OS isn't taking care of it for you.

If the program expects an operating system to be available to it the relationship is that the OS abstracts away hardware details and determines when the program gets to run (multithreaded OS or not). The OS can also halt a program.

If the program doesn't expect an operating system it maybe an operation system itself. Or it may just be a dedicated program for that hardware.

If we're talking about Java, well there's this Virtual Machine that tries to make every hardware and OS look the same to the program so it can work on any hardware and any OS. This abstracts away details so the program doesn't have to care what it's running on.

The essential relationship is programs need things outside themselves to work properly. The operation system may be one of those things.

0

An entire book is needed to answer your question. Read Operating Systems: Three easy pieces.

See also Operating System, Process, Virtual Address Space, Executable, Scheduling wikipages.

In a few words, a source program is often compiled into an executable (which contains machine code that processors can execute, and other information; see e.g. ELF). A process is a running instance of an executable. It has its own virtual address space (perhaps shared between the several threads of that process). You can have several processes running the same program (e.g. my Linux shell zsh is running in several terminals, and when I compile a big program using make -j to get a parallel build I have several processes running the cc1plus internal compiler program started by g++). A process is requesting operations provided by the operating system kernel (e.g. reading some file) thru system calls.

Most common operating systems (Linux, Unix, MacOSX, Android, Windows) have processes like explained above. But some weird operating systems have different approaches and designs, e.g. unikernels like MirageOS, or persistent operating systems like Grasshopper. Sometimes, these weird operating systems (e.g. Singularity) want baroque programming languages (because they are language-based systems) and/or specific hardware (see Crash-SAFE project).

protected by gnat Dec 16 '16 at 7:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.