Chapter 3: Process Management
Processes, Threads, Process States, PCB & CPU Scheduling Fundamentals
This is the most important chapter of Operating Systems. Almost every OS exam contains questions from: Process, Thread, PCB, Process States, Scheduling, and Context Switching.
1. What is a Process?
A process is a program in execution.
Program vs Process
| Feature | Program | Process |
|---|---|---|
| Nature | Passive entity | Active entity |
| Location | Stored on disk | Loaded into memory and executing |
| Example | chrome.exe, calculator.exe | Chrome running, Music Player running |
Simple Analogy: Recipe vs Cooking
- Recipe = Program (stored in a book, doing nothing)
- Cooking = Process (someone follows the recipe and actively cooks)
Process Components
Every process contains four sections in memory:
| Section | Stores |
|---|---|
| Code (Text Section) | Actual program instructions |
| Data Section | Global variables |
| Stack | Function calls, local variables, return addresses |
| Heap | Dynamically allocated memory (malloc(), new) |
| Process Memory Layout |
|---|
| Stack (grows downward) |
| Heap (grows upward) |
| Data Section |
| Code Section |
2. Process States
During execution, a process moves through several states.
Five-State Model
| State | Description | Example |
|---|---|---|
| 1. New | Process is being created | You double-click Chrome — OS creates a new process |
| 2. Ready | Process is waiting for CPU, ready to execute | Chrome loaded into memory but CPU not assigned yet |
| 3. Running | CPU is actively executing instructions | Chrome actually rendering a page |
| 4. Waiting (Blocked) | Process waiting for an event to complete | Waiting for disk read, keyboard input, or network response |
| 5. Terminated | Execution completed, process removed from system | Closing Chrome |
| State Transition Flow |
|---|
| NEW → READY → RUNNING → WAITING → READY → RUNNING → TERMINATED |
| Quick Exam Questions | Answer |
|---|---|
| Which state waits for CPU allocation? | ✅ Ready State |
| Which state waits for I/O completion? | ✅ Waiting (Blocked) State |
3. Process Control Block (PCB)
PCB is a data structure used by the OS to store all information about a process. Every process has its own PCB.
PCB Contents
| Field | Description |
|---|---|
| Process ID (PID) | Unique identifier for the process |
| Process State | Current state: Ready, Running, Waiting, etc. |
| Program Counter | Address of the next instruction to execute |
| CPU Registers | Current values of all CPU registers |
| Scheduling Information | Priority, queue position |
| Memory Information | Allocated memory regions |
| Accounting Information | CPU usage, execution time |
📌 Why PCB is Important: During context switching, the OS saves the current process state into its PCB, and later restores it to resume execution exactly where it left off.
4. Process Operations
| Operation | Description | Example |
|---|---|---|
| Creation | New process enters the system | Opening a browser or starting an application |
| Execution | CPU executes process instructions | Browser loading a page |
| Termination | Process finishes and is removed | Closing the browser |
5. Parent and Child Processes
A process can create another process, forming a parent-child relationship.
| Type | Description |
|---|---|
| Parent Process | Creates another process |
| Child Process | Created by the parent process |
Example: Chrome Browser (parent process) creates: Tab 1 process, Tab 2 process, Extension process as children.
6. Threads
A thread is the smallest unit of CPU execution.
Analogy: A process is like a house. Threads are the rooms inside that house.
Example: Chrome Browser Process contains: UI Thread, Rendering Thread, Network Thread all running concurrently.
Why Threads? Without threads, one slow task blocks everything. With threads, tasks execute concurrently within the same process.
| Thread Has (Own) | Threads Share (with other threads) |
|---|---|
| Program Counter | Code section |
| Registers | Data section |
| Stack | Heap |
Process vs Thread
| Feature | Process | Thread |
|---|---|---|
| Weight | Heavyweight | Lightweight |
| Memory | Own separate memory space | Shares memory with other threads |
| Creation Cost | Expensive | Cheap |
| Communication | Slower (IPC needed) | Faster (shared memory) |
| Unit | Resource ownership unit | CPU execution unit |
Types of Threads
| Feature | User-Level Thread | Kernel-Level Thread |
|---|---|---|
| Managed By | User libraries | OS kernel |
| Speed | Faster | Slower |
| Overhead | Less | More |
| Kernel Awareness | Kernel unaware | Kernel aware |
| Control | Limited | Better control |
7. CPU Scheduling
CPU Scheduling is the process of selecting which process gets the CPU next. Many processes compete for one CPU, and the OS decides who runs first, who waits, and for how long.
Scheduling Objectives
| Objective | Goal |
|---|---|
| 1. Maximize CPU Utilization | Keep CPU as busy as possible |
| 2. Maximize Throughput | Complete more processes per unit time |
| 3. Minimize Waiting Time | Reduce time spent in the ready queue |
| 4. Minimize Turnaround Time | Finish processes as quickly as possible |
| 5. Minimize Response Time | Respond faster to user requests |
Important Formulas
| Metric | Formula | Meaning |
|---|---|---|
| Turnaround Time (TAT) | TAT = Completion Time − Arrival Time |
Total time from arrival to completion |
| Waiting Time (WT) | WT = TAT − Burst Time |
Time spent waiting in ready queue |
| Response Time (RT) | RT = First CPU Time − Arrival Time |
Time before first CPU allocation |
Worked Example
| Field | Value |
|---|---|
| Arrival Time | 0 sec |
| Burst Time | 5 sec |
| Completion Time | 8 sec |
| TAT | 8 − 0 = 8 |
| WT | 8 − 5 = 3 |
8. Schedulers
| Scheduler | Role | Activity Level |
|---|---|---|
| Long-Term Scheduler | Controls admission of new jobs into the system | Least active |
| Short-Term Scheduler | Chooses the next process to get CPU from the ready queue | Most active |
| Medium-Term Scheduler | Temporarily removes (swaps out) processes from memory to reduce load | Moderate |
📌 Memory Trick — LSM: L → Load jobs | S → Select CPU | M → Move processes
9. Dispatcher
The Dispatcher is the component that actually gives the CPU to the process selected by the short-term scheduler.
| Dispatcher Responsibility |
|---|
| Performing context switching |
| Switching to user mode |
| Jumping to the correct location in the program to restart execution |
Dispatch Latency: Time required to switch the CPU between processes. Lower is better.
10. Context Switching
Definition: Saving the state of the current process into its PCB and restoring the state of another process from its PCB.
| Step | Action |
|---|---|
| 1 | Save Process A state into PCB-A |
| 2 | Load Process B state from PCB-B |
| 3 | Resume Process B execution |
⚠️ Important Fact: Context switching is pure overhead. The CPU performs no useful work during the switch itself.
Process Lifecycle Summary
| Lifecycle Stage |
|---|
| Process Created → NEW |
| ↓ READY |
| ↓ RUNNING |
| ↓ WAITING (if I/O needed) |
| ↓ READY (after I/O done) |
| ↓ RUNNING |
| ↓ TERMINATED |
Memory Tricks
| Mnemonic | Full Form |
|---|---|
| Process States — NRRWT |
N → New R → Ready R → Running W → Waiting T → Terminated |
| PCB Components — PSPRMA |
P → PID S → State P → Program Counter R → Registers M → Memory Info A → Accounting Info |
| Scheduling Goals — CUTWRR |
C → CPU Utilization U → User Response T → Throughput W → Waiting Time R → Response Time |
Frequently Asked Exam Questions
| Question | Program | Process |
|---|---|---|
| Q1. Difference between Program and Process? | Passive, stored on disk | Active, running in memory |
| Question | Process | Thread |
|---|---|---|
| Q2. Difference between Process and Thread? | Heavyweight, separate memory | Lightweight, shared memory |
- Q3. What is PCB? → A data structure storing all information about a process.
- Q4. Which state waits for CPU? → Ready
- Q5. Which state waits for I/O? → Waiting (Blocked)
Practice MCQs
-
1. A program in execution is called:
A. File B. Process C. Thread D. Scheduler
✅ Answer: B — Process -
2. Which data structure stores process information?
A. Cache B. PCB C. Stack D. Heap
✅ Answer: B — PCB (Process Control Block) -
3. Which state indicates a process waiting for I/O?
A. Ready B. Running C. Waiting D. New
✅ Answer: C — Waiting (Blocked) -
4. Thread is:
A. Heavyweight process B. CPU execution unit C. Scheduler D. Device Driver
✅ Answer: B — CPU execution unit -
5. Which scheduler selects the next process for CPU?
A. Long-term B. Medium-term C. Short-term D. Job Scheduler
✅ Answer: C — Short-term Scheduler