1Definition
A Program is a passive executable file stored on secondary disk storage containing compiled machine code instructions. A Process is an active program under execution loaded into primary RAM memory. A process memory layout is partitioned into four distinct segments: Text Segment, Data Segment, Heap Segment, and Stack Segment.
2Simple Explanation
Think of a program as a written recipe printed in a cookbook on a shelf (passive, sitting on a hard drive). A process is the actual act of cooking that recipe in a kitchen (active, in RAM, consuming resources). When the OS transforms a program file into an active process, it carves out a specific block of RAM and divides it into sections: one for the code instructions, one for global variables, one for dynamic memory requests (malloc), and one for tracking active function calls and local variables.
3Real-Life Example / Analogy
- Program: A blueprint of a house stored in an architect's drawer (Disk file).
- Process: The active construction site with workers, cranes, and concrete mixers building the house (RAM execution).
4Diagram / Visual Representation
5Working / How It Works
- Program Loading: OS reads compiled binary from disk into RAM.
- Static Space Setup: OS allocates fixed memory addresses for Text (code) and Data (global variables) segments.
- Dynamic Memory Initialization: OS allocates runtime Stack (top of address space) and Heap (above data segment).
- Environment Setup: OS sets up I/O streams (
stdin,stdout), populates registers, and transfers execution control to themain()function entry point.
6Types / Components / Characteristics
- Process Memory Segments:
- Text Segment: Contains compiled machine code instructions loaded directly from storage. Read-only to prevent self-modification.
- Data Segment: Contains global and static variables initialized by the developer.
- Heap Segment: Manages runtime dynamic memory allocation (
malloc()in C,newin C++). Grows upward toward higher memory addresses. - Stack Segment: Stores temporary function stack frames, local variables, function parameters, and return addresses. Grows downward toward lower memory addresses.
7Solved Examples / Problems
Problem: Identify which process memory segment stores each of the following variables:
int global_count = 100;char *buffer = (char*) malloc(1024);int local_temp = 5;void calculate_sum() { ... }Solution:global_count-> Data Segment (Global initialized variable).- Pointer target
1024 bytes-> Heap Segment (Dynamically allocated viamalloc). local_temp-> Stack Segment (Local function variable).calculate_sum()binary machine instructions -> Text Segment (Executable code).
8Advantages, Disadvantages & Applications
- Segmented Architecture Advantages: Enforces memory protection (Text segment read-only), enables stack/heap dynamic expansion without memory overlap.
- Disadvantages: Stack overflow occurs if recursive functions grow the stack into unallocated heap territory.
9Important Points to Remember
- Stack grows downward; Heap grows upward.
- Programs are passive disk entities; Processes are active RAM entities.
10Test Your Understanding
- MCQ: Which memory segment of a process handles dynamic memory allocation generated by
malloc()?- A) Stack Segment
- B) Text Segment
- C) Heap Segment
- D) Data Segment
Show answer
C. - Conceptual Question: Detail the 5-step process an operating system executes to convert a passive disk program into an active running process.
- Application Question: Explain what happens to the process stack and system state when a function engages in infinite recursion.
