Topic 3.1 · Process & Thread Management

Programs, Processes & Process Memory Architecture

3 min read1 question to test yourself

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

STACK
Local variables · arguments · return addresses
Grows downward

Free space

HEAP
Dynamic allocation · malloc / new
Grows upward

DATA SEGMENT
Global and static variables

TEXT SEGMENT
Program instructions

5Working / How It Works

  1. Program Loading: OS reads compiled binary from disk into RAM.
  2. Static Space Setup: OS allocates fixed memory addresses for Text (code) and Data (global variables) segments.
  3. Dynamic Memory Initialization: OS allocates runtime Stack (top of address space) and Heap (above data segment).
  4. Environment Setup: OS sets up I/O streams (stdin, stdout), populates registers, and transfers execution control to the main() 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, new in 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:

  1. int global_count = 100;
  2. char *buffer = (char*) malloc(1024);
  3. int local_temp = 5;
  4. void calculate_sum() { ... } Solution:
  5. global_count -> Data Segment (Global initialized variable).
  6. Pointer target 1024 bytes -> Heap Segment (Dynamically allocated via malloc).
  7. local_temp -> Stack Segment (Local function variable).
  8. 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

  1. 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.
  2. Conceptual Question: Detail the 5-step process an operating system executes to convert a passive disk program into an active running process.
  3. Application Question: Explain what happens to the process stack and system state when a function engages in infinite recursion.

Finished this topic?

0 of 27 topics read in Operating Systems

Handwritten notes for the exam

Unit-wise SPPU notes and PYQs for this subject.

Helpful? Share it with your class

Free for everyone, no login needed.

Share topic