OPERATING SYSTEMS/Student Engineering Notebook
Page 03·notes
PROCESSES, THREADS & CONCURRENCY—~18 MIN READ·GATE CS LENS

The Process Concept, Memory Layout & The PCB

“How the OS breathes life into passive disk binaries, structuring virtual memory and PCB control blocks.”

1.Program vs. Process: The Fundamental Separation

A program is completely passive: it is a collection of compiled bytes, instructions, and static data resting silently in secondary storage (like an executable .exe or ELF binary on disk).

A process, in contrast, is an active entity. It is a program in execution, endowed with its own virtual address space, a Program Counter tracking its next instruction, CPU register states, open file descriptors, and dedicated memory segments.

Think of a program as a written musical score resting in a drawer; a process is the orchestra actively performing that score in real time.

mental model— Mental Model: Passive Recipe vs. Active Cooking

A cookbook recipe is a program. The chef reading the recipe, utilizing kitchen tools, and tracking current progress is the process.

2. The Anatomy of Process Memory

LIVE EXAM DRAWING STUDIOProgramming in C · 8 Marks

C Program Memory Architecture & Stack Frame

Standard 8-Mark University Exam Memory Layout Question

Step 1 of 4 · Exam Sheet View
0xFFFFFFFF (High Memory)0x00000000 (Low Memory)TEXT / CODE SEGMENTBinary Machine Instructions (Read-Only)
Step 1: Text Segment (Code) & Read-Only Memory

Draw low memory base: Text / Code segment (binary machine instructions).

2 Marks: Segment placement & address direction.
✍️ HOW TO DRAW ON EXAM ANSWER SHEET

Lowest memory addresses. Read-only to prevent self-modifying code. Shared among multiple running instances.

⚠️ COMMON EXAM BLUNDER / MARKS LOST

Placing Code segment at high memory.

✎ Tip:Low memory is at the bottom (0x00000000); High memory is at the top (0xFFFFFFFF).
Figure 2.1 — Canonical 32/64-bit Virtual Address Space Layout. Notice how the stack and heap grow toward each other into unallocated virtual memory.

3.The Four Core Memory Segments

Text Segment (Code): Contains the compiled machine instructions. This region is read-only and often shared among multiple instances of the same program to conserve physical RAM.

Data & BSS Segments: The initialized data segment holds global and static variables explicitly given values (e.g. int count = 10;). The BSS (Block Started by Symbol) segment stores uninitialized globals/statics, zero-initialized by the OS loader.

Heap Segment: Dynamically managed memory allocated at runtime via system calls (malloc(), calloc(), new). The heap grows upward from lower memory toward higher addresses.

Stack Segment: Holds local function call frames, parameters, local variables, and return addresses. On standard architectures (like x86/ARM), the stack grows downward from high memory toward lower addresses.

4. The Process Control Block (PCB)

Process Control Block (PCB)Pointer / PID:e.g. 1042Process State:READY / RUNNINGProgram Counter (PC):0x00401A20CPU Registers:EAX, EBX, ESP, EBPMemory Limits:Base & Limit / Page TableList of Open Files:stdin, stdout, socket#3✎ 1 PCB per process in OS Kernel Space · saved on every context switch
Figure 2.2 — Key fields encapsulated in the kernel-level Process Control Block (struct task_struct in Linux).

5. Architecture Comparison: Process vs. Thread

Understanding the exact resource boundaries is critical for both systems programming and GATE questions.

Feature / AspectProcessThread (Lightweight Process)
Address SpaceIsolated, private virtual memory space.Shares code, data, heap, and open files with peer threads.
Creation OverheadHeavyweight: Requires memory allocation, page tables, PCB creation.Lightweight: Minimal state allocation (private stack & TCB only).
Context SwitchingSlow: Flushes TLB cache, switches page tables (CR3) & registers.Fast: Switches only registers and stack pointer; TLB intact.
Failure IsolationHigh: One process crashing does not affect other processes.Low: An illegal memory access in one thread crashes all peer threads.

✎ Takeaway: Processes provide units of resource ownership and isolation; threads provide units of CPU dispatching and scheduling.

GATE LENS · EXAM PREPARATION

6. GATE Lens & Verified PYQs

Syllabus focus, recurring numerical patterns, common traps, and clearly labelled exam practice. Questions remain source-pending until an official paper and answer key are attached.

EXAM WEIGHTAGE & FOCUS:

Memory segment classification and thread resource sharing appear frequently in GATE CS (notably 2011, 2017, and 2021).

recurring exam patterns:
  • •Identifying which segment a given variable is allocated in (global, local, static, dynamic).
  • •Determining what program state is shared between threads vs kept strictly private.
⚠ common student traps:
  • •Forgetting that static local variables inside functions live in the DATA/BSS segment, NOT on the stack!
  • •Pointers allocated with malloc have their pointer variable on the stack, but the pointed-to buffer on the heap.

Exam Practice / Source Verification Required

1 problem
GATE-style question · 1 MarkThread private state = ==purple:Stack + CPU Registers (PC, SP) + State==.

Which of the following components of a program state are NOT shared among threads of the same process? (P) Code segment (Q) Global variables (R) Stack (S) CPU Register values

A. P and Q only
B. R and S only
C. Q and R only
D. S only
RAPID REVIEW · NOTEBOOK SUMMARY

7. 1-Minute Panic Revision

All Sheets→
core principle:

“Process = Program in execution with isolated virtual address space (Text + Data/BSS + Heap + Stack) + PCB.”

must-remember principles:
  • •Stack grows DOWNWARD (High → Low addresses); Heap grows UPWARD (Low → High addresses).
  • •Threads SHARE: Code, Globals/BSS, Heap, Open files.
  • •Threads KEEP PRIVATE: Stack, Registers, Program Counter (PC).
critical exam pitfalls:
  • •Static variables (even inside a local function block) live in DATA/BSS, never on the stack.
  • •PCB is maintained exclusively in kernel space; user code cannot read or overwrite its own PCB.
decision flow & invariants:
[ PROCESS MEMORY HIERARCHY & THREAD ISOLATION INVARIANT ] [ 0xFFFF: HIGH MEMORY ] ┌────────────────────────────────────────────────────────┐ │ STACK (Local function frames, return addresses) │ Grows DOWNWARD (↓) ├────────────────────────────────────────────────────────┤ │ │ │ UNALLOCATED VIRTUAL MEMORY │ (Collision triggers │ │ Stack Overflow) ├────────────────────────────────────────────────────────┤ │ HEAP (Dynamic memory via malloc() / new) │ Grows UPWARD (↑) ├────────────────────────────────────────────────────────┤ │ BSS SEGMENT (Uninitialized global & static vars = 0) │ ├────────────────────────────────────────────────────────┤ │ DATA SEGMENT (Initialized global & static vars) │ ├────────────────────────────────────────────────────────┤ │ TEXT SEGMENT (Binary machine instructions - Read-Only)│ └────────────────────────────────────────────────────────┘ [ 0x0000: LOW MEMORY ] THREAD INVARIANT: SHARED across Threads : Text, Data, BSS, Heap, Open Files. PRIVATE to Each Thread : Stack, Registers, Program Counter (PC).
SOURCE TRANSPARENCY & CITATIONS

Primary Academic References & Exam Sources

Every concept in Notes From a B.Tech Brain is synthesized from authoritative academic texts, seminal peer-reviewed research, verified exam archives, and renowned university lectures.

Primary Academic Texts
Operating System Concepts (10th Edition)↗by Silberschatz, Galvin, Gagne · Chapter 3: Processes (Section 3.1: Process Concept, Memory Layout & The PCB)

Official slides showing the memory layout (Text, Data, BSS, Heap, Stack) and Process Control Block fields.

ACADEMIC STANDARD
Operating Systems: Three Easy Pieces (OSTEP)↗by Remzi H. Arpaci-Dusseau & Andrea C. Arpaci-Dusseau · Chapter 4: The Abstraction: The Process (Process Creation & Memory Layout)

Clear introduction to process address space initialization, PCB structures in xv6, and process APIs.

ACADEMIC STANDARD
ALTERNATIVE PEDAGOGICAL PERSPECTIVES

If the textbook derivation did not click immediately, consult these targeted video lessons:

Process Memory Layout and PCB in Operating SystemGate Smashers (Varun Singla) (11 mins)

Practical breakdown of what goes into Data vs BSS vs Stack vs Heap with C memory examples.

Watch Lesson↗
Process vs Thread in Operating SystemNeso Academy (12 mins)

Clean blackboard lecture showing what threads share in RAM versus what remains private (registers, PC, stack).

Watch Lesson↗
RECOMMENDED YOUTUBE LECTURES & EDUCATORS: MODULE 2: PROCESSES, THREADS & CONCURRENCY

Curated lectures on Process Lifecycle, PCB Memory Layout, Fork() System Calls & Multi-threading Models:

Gate Smashers · L-1.5: Process States in OS & Schedulers↗Instructor: Varun Singla · Covers: 5-State vs 7-State Process Life Cycle, Suspended states, Long/Medium/Short-term schedulers

Rapid intuitive mastery of process state transitions and state diagram numericals.

Open YouTube↗
Gate Smashers · L-1.12: User Level vs Kernel Level Threads↗Instructor: Varun Singla · Covers: User-Level Threads (ULT) vs Kernel-Level Threads (KLT), TCB structure, Concurrency models

Clear breakdown of blocking I/O behavior, thread context switches, and kernel space mapping.

Open YouTube↗
Neso Academy · fork() and exec() System Calls Walkthrough↗Instructor: Neso Academy · Covers: fork() execution trees, Return values (PID > 0, PID == 0), Zombie and Orphan processes

Visual tree diagram derivations of fork() return values and process hierarchies.

Open YouTube↗
Knowledge Gate · Process vs Thread & Fork GATE Numericals↗Instructor: Sanchit Jain · Covers: GATE PYQ derivations on nested fork() loops, shared vs private thread resources, PCB fields

Exam trick cases on how many times printf() executes in tricky fork() loops.

Open YouTube↗