operating-systems

Definition

Process

A process is an instance of a computer program that is being executed. It serves as the unit of resource management, encompassing the program code, its current activity (represented by the program counter and registers), and the allocated resources (memory segments, file handles, etc.). While a program is a static collection of instructions, a process is a dynamic entity that represents the “animated spirit” of that program during its lifecycle.

Quasi-Parallelism: The Film Analogy

Operating systems create the illusion of parallelism by rapidly alternating between different processes. This is analogous to how an analogue film creates the impression of a continuously moving picture:

  • Snipping: Just as a film is broken down into a sequence of individual static images, the execution of programs is broken into many small pieces (time slices).
  • Interleaving: The gaps in one program’s execution are used to play sections of other programs.
  • Persistence of Vision: If this alternation (performed by the dispatcher) happens fast enough, the user perceives all processes as running simultaneously.

Process vs. Program: The Train Analogy

The relationship between a program and a process is analogous to that of a train and a train journey:

  • Program (Train): A static object with a fixed structure (wagons, seats). It describes the potential movement but is inherently stationary.
  • Process (Train Journey): The dynamic execution of the program. It involves movement, changing positions, varying speeds, and the occupation of seats by different passengers at different times.
FeatureProgramProcess
NatureStaticDynamic
Life SpanPersistent (stored on disk)Transient (exists during execution)
ResourcesOccupies disk spaceOccupies CPU, RAM, and I/O
MultiplicityOne program……can result in multiple processes

Components

A process consists of:

  • Text: The machine code instructions.
  • Program Counter: The address of the next instruction to be executed.
  • Stack: A LIFO structure for function calls and local variables.
  • Data: Global variables and dynamic memory (heap).
  • Resources: Handles to open files, network connections, and other system resources.
  • Instruction Trace: The actual sequence of instructions executed by the processor for the process.

The operating system manages this state within a Process Control Block (PCB).

Lifecycle and States

The OS manages the execution of multiple processes by alternating their access to the CPU, creating an “illusion of parallelism.” The transitions between different phases of execution are described by the Process State Model.

Termination and Clean-up

When a process finishes execution, the OS must clean up its resources. Two special cases can occur during termination:

  • Zombie Process: A process that has terminated but still has an entry in the process table because its parent process hasn’t yet read its exit status.
  • Orphan Process: A process whose parent has terminated. These are typically “adopted” by the init process (PID 1), which periodically cleans up zombie children.