ADVERTISEMENT
Responsive Ad Unit • Systems Architecture & Low-Level Engineering

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

Program stored on disk
Calculator
↓
User starts it
↓
Operating System creates
Process

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).

chrome.exe
↓
Process 101
↓
Process 205
↓
Process 310

Same program.
Different processes.
Each has its own execution context.

3. Process Components

Every process contains several memory regions.

+--------------------------+
Code (Text Segment)
--------------------------
Initialized Data
--------------------------
Uninitialized Data (BSS)
--------------------------
Heap
↑
↓
Stack
+--------------------------+

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

High Address
+----------------+
Stack
↓
-----------------
Free Space
-----------------
Heap
↑
-----------------
BSS
-----------------
Data
-----------------
Code
+----------------+
Low Address

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

New
↓
Ready
↓
Running
↓
Waiting
↓
Ready
↓
Running
↓
Terminated

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)
Process State
Program Counter
CPU Registers
Stack Pointer
Priority
Scheduling Information
Memory Information
Open Files
Accounting Information
+---------------------------+

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

+----------------------------------+
PID
State
Program Counter
Stack Pointer
CPU Registers
Priority
Page Table Pointer
Open Files
Signal Information
Accounting Information
+----------------------------------+

7. Process Creation

When a process starts,
the operating system performs:

Create PCB
↓
Assign PID
↓
Allocate Memory
↓
Initialize Registers
↓
Load Program
↓
Ready Queue

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

Release Memory
↓
Close Files
↓
Remove Scheduling Entries
↓
Cleanup PCB

9. Parent and Child Processes

Many operating systems allow one process to create another.

Example

Parent
↓
Create
↓
Child

In Unix-like systems this is commonly performed using fork().

Example

Shell
↓
Creates
↓
Text Editor
↓
Creates
↓
Compiler

Each process receives its own PID.

10. Context Switching

Suppose
Process A
is running.
Timer interrupt occurs.

Operating system performs

Save Process A Registers
↓
Save Program Counter
↓
Save Stack Pointer
↓
Update PCB
↓
Load PCB of Process B
↓
Restore Registers
↓
Restore Program Counter
↓
Resume Process B

This is called a context switch.

Visualization

CPU
↓
Process A
↓
Save Context
↓
PCB A
↓
Load PCB B
↓
Process B

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

Finished
↓
PCB Still Exists
↓
Zombie

It occupies only minimal kernel resources, mainly its process table entry.

12. Orphan Process

Suppose
Parent exits
before
Child.

Parent
↓
Terminates
↓
Child Continues

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

  1. What is the difference between a program and a process?
  2. What is a PCB?
  3. Why does the operating system need a PCB?
  4. Name the five classical process states.
  5. What information is stored in a PCB?
  6. What is a context switch?
  7. Why is the Program Counter saved during a context switch?
  8. What is the difference between a zombie and an orphan process?
  9. What happens when a process enters the Waiting state?
  10. Why does every process have a unique PID?
Knowledge Check

Concept Mastery Assessment — Module 13

Verify your conceptual understanding with 12 targeted technical assessment questions. Instant feedback and explanations are provided for every choice.

Question 1 of 12
What is the fundamental difference between a 'program' and a 'process'?
Explanation
A program is a passive binary artifact on storage. A process is an active entity with a Program Counter, registers, stack, heap, and open file descriptors.
Question 2 of 12
Which of the following is NOT typically stored inside the Process Control Block (PCB / struct task_struct in Linux)?
Explanation
The PCB stores OS metadata (PID, state, credentials, registers, memory pointers, open files), never high-level application source code.
Question 3 of 12
In the standard 5-state process lifecycle model, what state does a process transition to when waiting for an I/O disk read to complete?
Explanation
A process blocks (transitions to Waiting/Blocked) when requesting an I/O operation. Once I/O completes, the interrupt handler moves it to Ready.
Question 4 of 12
What is a 'context switch' in an operating system?
Explanation
A context switch saves the CPU register state, Program Counter, and stack pointer of the outgoing process to its PCB and loads the incoming process's state.
Question 5 of 12
What is the primary computational overhead associated with a context switch between two different processes?
Explanation
Beyond the direct register-save overhead, switching address spaces causes TLB invalidation and cache locality loss, incurring memory stalls.
Question 6 of 12
In Linux, what is the core C struct that represents a process or thread inside the kernel?
Explanation
Linux represents every process and thread uniformly using 'struct task_struct' defined in <linux/sched.h>.
Question 7 of 12
What distinguishes TASK_INTERRUPTIBLE from TASK_UNINTERRUPTIBLE process states in Linux?
Explanation
TASK_INTERRUPTIBLE wakes on signals or events. TASK_UNINTERRUPTIBLE (state D) waits on critical hardware I/O and cannot be killed until the I/O returns.
Question 8 of 12
What is a 'Zombie' process (state EXIT_ZOMBIE in Linux)?
Explanation
A zombie has released all its memory and file descriptors, but retains an entry in the process table so its parent can read its exit code.
Question 9 of 12
What is an 'Orphan' process, and what does the Linux kernel do when a process becomes orphaned?
Explanation
When a parent exits before its child, the child becomes an orphan. The kernel reparents the orphan to PID 1 (init/systemd), which reaps it upon exit.
Question 10 of 12
Which virtual filesystem in Linux allows user-space programs to inspect kernel PCB attributes and process runtime statistics?
Explanation
/proc is a pseudo-filesystem generated dynamically by the kernel; each process has a directory `/proc/[pid]` containing status, memory maps, and fds.
Question 11 of 12
What process state transition occurs when the CPU scheduling timer quantum expires for a running process?
Explanation
When a process exhausts its allotted time slice (quantum), the timer interrupt handler preempts it, transitioning it from Running back to Ready.
Question 12 of 12
In Linux, what is the maximum PID value by default on a 64-bit system, and where can it be tuned?
Explanation
Default PID maximum is 32768 or 4,194,304 on 64-bit Linux systems, configured via `/proc/sys/kernel/pid_max`.
0 / 12 (0%)
Great job! Review the concepts above and proceed when ready.
ADVERTISEMENT
Responsive Ad Unit • Technical Courses & Certifications