Difference between Program and Process

Program Vs Process

A program is a static set of instructions written in a programming language such as C, C++, or Go. It is stored in a file—often a binary with an .exe extension on Windows—and is the output of a compilation process. Examples of programs include Notepad, VSCode, or a custom-built application. The source code of a program represents the logic and behavior a programmer wants the operating system to execute when the program is run.

In contrast, a process is a program in execution.

A process is an instance of a program that is being executed by the operating system.

This definition is technically correct but oversimplified. It doesn't fully reflect the complexities involved when a program transitions to a running process.


Application Lifecycle


🔍 What Happens When a Program Becomes a Process

When you execute a program, the operating system loads it into memory and creates a process. This process is more than just the code—it consists of several memory segments collectively referred to as the process layout:

  • TEXT segment: Contains the compiled program instructions (code). This is typically read-only.
  • DATA segment: Contains global and static variables initialized by the program.
  • HEAP: Used for dynamic memory allocation during runtime. Its size can grow or shrink as needed.
  • STACK: Stores local variables, function parameters, return addresses, and handles function call management. Like the heap, it can also grow and shrink dynamically.

The OS reads instructions from the TEXT segment and begins executing them—loading variables into CPU registers, performing computations, making system calls, and updating memory. Any runtime-created data (like objects, buffers, etc.) gets stored in the HEAP or STACK depending on how it's allocated.


Process Layout


🌀 Multiple Executions of the Same Program

When the same program is run multiple times (e.g., opening two instances of Notepad), the OS creates separate processes for each execution. Each process has:

  • Its own memory layout (separate STACK and HEAP)
  • Independent runtime state (registers, program counter, etc.)
  • Separate process ID (PID)

This allows the same program to run concurrently in isolation, without interference between instances.

🚀 Final Notes

What’s described here is just the tip of the iceberg. Processes involve complex scheduling, inter-process communication (IPC), synchronization, privilege separation, and more. Running processes reliably and concurrently is one of the most important and intricate responsibilities of an operating system.

© UNTITLED | Website created by Rupam Joshi