Operating Systems
Process Control Block (PCB); Process States; CPU Scheduling
C-CAT
Process Control Block (PCB)
What is a PCB?
The PCB (Process Control Block) is the data structure used by the OS to store all information about a process.
Also called: Task Control Block (TCB)
PCB Contents
| Field | Description |
|---|---|
| Process ID (PID) | Unique identifier for the process |
| Process State | New, Ready, Running, Waiting, Terminated |
| Program Counter (PC) | Address of next instruction to execute |
| CPU Registers | Contents of all CPU registers (saved on context switch) |
| CPU Scheduling Info | Priority, scheduling queue pointers |
| Memory Management Info | Base register, limit register, page/segment tables |
| I/O Status Info | List of open files, I/O devices allocated |
| Accounting Info | CPU time used, elapsed time, job limits |
| Parent PID (PPID) | PID of parent process |
| User ID (UID) | Owner of the process |
Process States
Five-State Process Model
+--------+
| NEW | ← Process created
+--------+
| admitted
↓
+------READY------+
| ←scheduler |
| dispatch |
↓ | interrupt / time slice
+--------+ |
|RUNNING |→→→→→→→→→→→→+
+--------+
|
| Wait for I/O or event
↓
+--------+
|WAITING | ← process blocked for I/O
| (BLOCKED)|
+--------+
|
| I/O or event complete
↓
READY (returns to Ready queue)
RUNNING → TERMINATED (exit)
Process States Explained
| State | Description | Transitions |
|---|---|---|
| New | Process is being created | → Ready (after creation) |
| Ready | In memory, waiting for CPU | → Running (scheduler dispatches) |
| Running | Actually being executed on CPU | → Ready (time slice expires) / Waiting (I/O) / Terminated (exit) |
| Waiting (Blocked) | Waiting for I/O completion or event | → Ready (I/O/event done) |
| Terminated | Process has finished execution | End state |
Context Switch
When CPU switches from one process to another:
Process A running on CPU
|
| Interrupt / time expired
↓
Save CPU state of A → PCB_A
Load CPU state of B ← PCB_B
|
| Process B now running on CPU
Context switch overhead: Saving and restoring registers, cache flush — expensive!
CPU Scheduling
What is CPU Scheduling?
CPU Scheduling selects which process in the Ready queue gets the CPU next.
Why scheduling?
- CPU can only run one process at a time
- Multiple processes compete for CPU
- OS must decide who runs next
Scheduling Queues
New Process → Job Queue
↓
Ready Queue (in RAM)
↓
CPU Scheduler picks one
↓
CPU executes process
↓
I/O request? → I/O Wait Queue → I/O done → Ready Queue
Time slice? → Preempted → Ready Queue
Exit? → Terminated
Scheduling Criteria (Performance Metrics)
| Metric | Description | Optimize |
|---|---|---|
| CPU Utilization | Percentage of time CPU is busy | Maximize |
| Throughput | Number of processes completed per time unit | Maximize |
| Turnaround Time | Total time from submission to completion | Minimize |
| Waiting Time | Total time process spends in ready queue | Minimize |
| Response Time | Time from submission to first response | Minimize |
Formulas:
Turnaround Time = Completion Time - Arrival Time
Waiting Time = Turnaround Time - Burst Time
Response Time = First CPU given - Arrival Time
Preemptive vs Non-Preemptive Scheduling
| Type | Description |
|---|---|
| Non-Preemptive | Once CPU is given to a process, it keeps it until done or waiting for I/O |
| Preemptive | OS can forcibly take CPU from running process (time slice, priority) |
Continue learning
Related notes
Definition of AI; Need of AI
Artificial Intelligence
Introduction to Data Engineering; Big Data — The 5 V's; Types of Data
Big Data and Data Engineering
Introduction to C Programming; C Program Structure; Data Types and Variables
C Programming
What Is a Computer?; Machine Cycle: Fetch–Decode–Execute; CPU Organization
Computer Architecture
Put this topic into timed practice
Open mock tests when you want full-exam pacing, or keep drilling in practice mode.