Facebook Pixel

In modern Operating Systems, a process is fundamentally defined as a program in execution. It is the basic unit of work in a modern time-sharing system.

When you double-click a web browser icon or run a compiled C program from the terminal, the Operating System allocates memory, loads the binary instructions into that memory, and begins executing them. At that exact moment, the static program transforms into an active, dynamic process.

Program vs. Process

To truly understand process management, one must deeply understand the distinction between a program and a process. They are closely related but represent two entirely different states of existence.

FeatureProgramProcess
NaturePassive entity (a static file stored on secondary storage like an SSD).Active entity (loaded into main memory/RAM and executing).
LifespanPermanent (exists as long as the file is not deleted).Temporary (exists only until the execution is completed or terminated).
ResourcesRequires only disk space to store the file.Requires CPU time, RAM, I/O devices, and OS data structures.
StateStateless. It is just a set of instructions.Stateful. It has a current context, program counter, and dynamic memory.
One Program, Multiple Processes
A single program can be associated with multiple processes. For example, if you open five different windows of Google Chrome, the OS spawns five separate processes, all executing the exact same underlying binary program. Each will have its own independent memory space and process ID.

Process Memory Layout

When a process is loaded into RAM, the Operating System does not just dump the data randomly. It heavily structures the memory into distinct, organized segments. This layout allows for efficient resource management and memory protection.

Process Architecture in RAM
High Address
+------------------+
|      Stack       | -> Local variables, function params, return addresses
|        |         |
|        v         |
|                  |
|        ^         |
|        |         |
|      Heap        | -> Dynamically allocated memory (malloc, calloc, new)
+------------------+
| Uninitialized    | -> BSS segment (Uninitialized global/static variables)
|      Data        | 
+------------------+
| Initialized      | -> Data segment (Initialized global/static variables)
|      Data        |
+------------------+
|      Text        | -> The compiled binary machine code (Read-Only)
+------------------+
Low Address

1. Text Section: Contains the compiled program code (machine instructions). This section is typically marked as *read-only* to prevent a process from accidentally modifying its own instructions.

2. Data Section: Contains global and static variables initialized by the programmer prior to execution (e.g., int x = 10;). Uninitialized globals go into the BSS segment and are initialized to zero.

3. Heap: Used for dynamic memory allocation during run time. When a programmer calls malloc() in C or new in C++/Java, memory is carved out of the heap. The heap grows *upwards* towards higher memory addresses.

4. Stack: Used for temporary data storage. It holds local variables, function parameters, and return addresses necessary for function calls. As functions are called, the stack grows *downwards* towards lower memory addresses.

Stack Overflow vs Memory Leak
If a program uses infinite recursion, the Stack will grow downwards until it collides with the Heap, causing a 'Stack Overflow'. Conversely, if a programmer continuously allocates Heap memory without freeing it, the Heap grows upwards, causing a 'Memory Leak' which eventually crashes the process.

Process Attributes and the PCB

Because an OS handles hundreds of active processes simultaneously, it requires a dedicated data structure to track the exact state and metadata of each process. This structure is called the Process Control Block (PCB), sometimes referred to as the Task Control Block.

Every time a process is created, the OS generates a unique PCB for it in the kernel memory.

AttributeDescription
Process ID (PID)A unique integer assigned by the OS to identify the process.
Process StateThe current status of the process (e.g., New, Ready, Running, Waiting, Terminated).
Program CounterStores the memory address of the very next instruction to be executed.
CPU RegistersSaves the contents of all CPU registers when the process is swapped out, allowing it to resume exactly where it left off.
Memory InfoContains the value of the base and limit registers, page tables, or segment tables.

Knowledge Check

Let's reinforce the technical concepts you've just learned. These interactions are purely for practice and do not affect your overall course progress.

Concept Validation

Question 1 of 3

Test your grasp on programs, processes, and memory architecture.

Which of the following statements regarding the Stack and Heap is true?
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.