Module 14 — Processes & Process Control Block (PCB)
Learning Objectives
By the end of this module, you will understand:
- What is a process?
- Program vs Process
- Process life cycle
- Process states
- Process Control Block (PCB)
- Process creation
- Process termination
- Parent and child processes
- Context switching
- Process identifiers (PID)
- Zombie and orphan processes
- Process scheduling overview
1. What is a Program?
A program is a passive collection of instructions stored on secondary storage.
Examples:
- Executable file
- Script
- Application binary
Example:
calculator.exe
or
app.out
A program does nothing until it is executed.
2. What is a Process?
A process is a program that is currently being executed.
Definition:
A process is an executing instance of a program along with its execution context and allocated resources.
Resources include:
- CPU registers
- Program Counter
- Stack
- Heap
- Open files
- Memory
- Process state
Example
Now CPU begins executing instructions.
Program vs Process
| Program | Process |
|---|---|
| Passive | Active |
| Stored on disk | Running in memory |
| Static | Dynamic |
| No execution state | Has execution state |
| One program file | Multiple processes can execute the same program |
Example
Suppose
chrome.exe
is stored on disk.
Opening three browser windows may create multiple processes (depending on browser architecture).
Same program.
Different processes.
Each has its own execution context.
3. Process Components
Every process contains several memory regions.
Code Segment
Contains executable instructions.
Example
printf("Hello");
Compiled machine code is stored here.
Typically
- Read
- Execute
permissions.
Data Segment
Stores initialized global and static variables.
Example
int count = 100;
BSS Segment
Stores uninitialized global and static variables.
Example
int value;
The operating system initializes this memory to zero before program execution begins.
Heap
Used for dynamic memory allocation.
Example
malloc()
calloc()
realloc()
The heap generally grows toward higher addresses.
Stack
Stores
- Local variables
- Function parameters
- Return addresses
- Stack frames
The stack typically grows toward lower addresses on many architectures, although this is architecture-dependent.
Process Memory Layout
4. Process States
A process does not execute continuously.
It moves through different states.
The classical five-state model:
+---------+
| New |
+---------+
|
v
+---------+
| Ready |
+---------+
|
v
+---------+
| Running |
+---------+
| |
I/O Wait| |Exit
v v
+---------+ +-----------+
|Waiting | |Terminated |
+---------+ +-----------+
|
v
Ready
New
The operating system is creating the process.
Actions:
- Allocate PCB
- Allocate memory
- Assign PID
- Initialize resources
Ready
The process is ready to run.
It is waiting for CPU time.
Many processes can be in the Ready state simultaneously.
Running
The CPU is currently executing this process.
Only one process per CPU core can be in the Running state at any instant.
Waiting (Blocked)
The process cannot continue until an event occurs.
Examples:
- Waiting for keyboard input
- Waiting for disk I/O
- Waiting for network data
- Waiting for a semaphore
CPU executes another ready process during this time.
Terminated
Execution has completed.
Operating system releases resources.
Eventually the PCB is removed after required cleanup.
5. State Transitions
Example
This is the normal life cycle of many processes.
6. What is a Process Control Block (PCB)?
The PCB is the operating system's data structure used to manage a process.
Definition:
A PCB contains all information required for the operating system to manage and resume a process.
Without the PCB,
context switching would not be possible.
PCB Contents
Typical fields include:
Process ID (PID)
Every process has a unique identifier.
Example
PID = 2541
Operating system uses the PID to identify the process.
Process State
Stores
- Ready
- Running
- Waiting
- Terminated
Program Counter
Stores the address of the next instruction to execute.
During a context switch,
the operating system saves the current Program Counter into the PCB.
CPU Registers
Registers such as
- R0
- R1
- ...
- SP
- PC
- Flags
are saved before switching to another process.
Stack Pointer
Indicates the current top of the process stack.
Necessary for resuming execution correctly.
Scheduling Information
Includes information such as:
- Priority
- Scheduling policy
- CPU usage statistics
Used by the scheduler.
Memory Information
Contains references to the process's memory structures.
Examples:
- Page table
- Virtual memory mappings
Open Files
The PCB keeps track of files currently opened by the process.
Example
- File1
- File2
- Socket
- Pipe
PCB Visualization
7. Process Creation
When a process starts,
the operating system performs:
The scheduler later selects it for execution.
8. Process Termination
A process may terminate because:
- It finishes normally.
- It calls an exit function.
- It encounters a fatal error.
- The operating system or another authorized process terminates it.
Then
9. Parent and Child Processes
Many operating systems allow one process to create another.
Example
In Unix-like systems this is commonly performed using fork().
Example
Each process receives its own PID.
10. Context Switching
Suppose
Process A
is running.
Timer interrupt occurs.
Operating system performs
This is called a context switch.
Visualization
The context switch allows multiple processes to share the CPU.
11. Zombie Process
A process has finished execution,
but its parent has not yet collected its exit status.
Result
It occupies only minimal kernel resources, mainly its process table entry.
12. Orphan Process
Suppose
Parent exits
before
Child.
The operating system assigns the orphaned child to a suitable system process (such as init or systemd on many Linux systems).
Interview Questions
Beginner
- What is a process?
- Difference between a program and a process?
- What are process states?
- What is a PCB?
Intermediate
- What information is stored in a PCB?
- Explain context switching.
- Why is the Program Counter stored in the PCB?
- Difference between stack and heap?
Senior
- Explain the complete process life cycle.
- Why is a PCB required?
- What happens during process creation?
- Explain zombie and orphan processes.
- Why does context switching introduce overhead?
Common Mistakes
- ❌ Thinking a program and a process are the same. A program is a file; a process is an executing instance.
- ❌ Assuming a process always runs continuously. Processes alternate between Ready, Running, and Waiting states.
- ❌ Believing the PCB stores the program code. The PCB stores process metadata, not the executable instructions.
- ❌ Thinking a zombie process is still executing. A zombie has already terminated.
Summary
A process is a running instance of a program together with its execution context and resources. The operating system manages each process through a Process Control Block (PCB), which stores the information needed for scheduling, execution, memory management, and context switching. Processes move through defined states from creation to termination, allowing the operating system to efficiently share CPU time among many executing programs.
Mini Quiz
- What is the difference between a program and a process?
- What is a PCB?
- Why does the operating system need a PCB?
- Name the five classical process states.
- What information is stored in a PCB?
- What is a context switch?
- Why is the Program Counter saved during a context switch?
- What is the difference between a zombie and an orphan process?
- What happens when a process enters the Waiting state?
- Why does every process have a unique PID?
Concept Mastery Assessment — Module 13
Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.