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.
| Feature | Program | Process |
|---|---|---|
| Nature | Passive entity (a static file stored on secondary storage like an SSD). | Active entity (loaded into main memory/RAM and executing). |
| Lifespan | Permanent (exists as long as the file is not deleted). | Temporary (exists only until the execution is completed or terminated). |
| Resources | Requires only disk space to store the file. | Requires CPU time, RAM, I/O devices, and OS data structures. |
| State | Stateless. It is just a set of instructions. | Stateful. It has a current context, program counter, and dynamic memory. |
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.
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 Address1. 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.
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.
| Attribute | Description |
|---|---|
| Process ID (PID) | A unique integer assigned by the OS to identify the process. |
| Process State | The current status of the process (e.g., New, Ready, Running, Waiting, Terminated). |
| Program Counter | Stores the memory address of the very next instruction to be executed. |
| CPU Registers | Saves the contents of all CPU registers when the process is swapped out, allowing it to resume exactly where it left off. |
| Memory Info | Contains 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 3Test your grasp on programs, processes, and memory architecture.
