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

FeatureProgramProcess
NaturePassive entityActive entity
LocationStored on diskLoaded into memory and executing
Examplechrome.exe, calculator.exeChrome 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:

SectionStores
Code (Text Section)Actual program instructions
Data SectionGlobal variables
StackFunction calls, local variables, return addresses
HeapDynamically 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

StateDescriptionExample
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 QuestionsAnswer
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

FieldDescription
Process ID (PID)Unique identifier for the process
Process StateCurrent state: Ready, Running, Waiting, etc.
Program CounterAddress of the next instruction to execute
CPU RegistersCurrent values of all CPU registers
Scheduling InformationPriority, queue position
Memory InformationAllocated memory regions
Accounting InformationCPU 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

OperationDescriptionExample
CreationNew process enters the systemOpening a browser or starting an application
ExecutionCPU executes process instructionsBrowser loading a page
TerminationProcess finishes and is removedClosing the browser

5. Parent and Child Processes

A process can create another process, forming a parent-child relationship.

TypeDescription
Parent ProcessCreates another process
Child ProcessCreated 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 CounterCode section
RegistersData section
StackHeap

Process vs Thread

FeatureProcessThread
WeightHeavyweightLightweight
MemoryOwn separate memory spaceShares memory with other threads
Creation CostExpensiveCheap
CommunicationSlower (IPC needed)Faster (shared memory)
UnitResource ownership unitCPU execution unit

Types of Threads

FeatureUser-Level ThreadKernel-Level Thread
Managed ByUser librariesOS kernel
SpeedFasterSlower
OverheadLessMore
Kernel AwarenessKernel unawareKernel aware
ControlLimitedBetter 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

ObjectiveGoal
1. Maximize CPU UtilizationKeep CPU as busy as possible
2. Maximize ThroughputComplete more processes per unit time
3. Minimize Waiting TimeReduce time spent in the ready queue
4. Minimize Turnaround TimeFinish processes as quickly as possible
5. Minimize Response TimeRespond faster to user requests

Important Formulas

MetricFormulaMeaning
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

FieldValue
Arrival Time0 sec
Burst Time5 sec
Completion Time8 sec
TAT8 − 0 = 8
WT8 − 5 = 3

8. Schedulers

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

StepAction
1Save Process A state into PCB-A
2Load Process B state from PCB-B
3Resume 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

MnemonicFull 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

QuestionProgramProcess
Q1. Difference between Program and Process?Passive, stored on diskActive, running in memory
QuestionProcessThread
Q2. Difference between Process and Thread?Heavyweight, separate memoryLightweight, 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