OS Notes
Detailed explanation of the Process Control Block — the data structure that represents a process in the OS, including its components, role in context switching, and implementation.
Introduction
Every student in a university has a file in the registrar's office. This file contains their name, ID number, courses enrolled, grades, contact information, and academic standing. Without these files, the university could not function — it would not know who is enrolled, what classes they are taking, or whether they have graduated. The Process Control Block (PCB) serves exactly this role for processes in an operating system.
The PCB is the data structure that the operating system uses to store all information about a process. It is the process's identity card, report card, and schedule all in one. When the OS needs to manage a process — schedule it, suspend it, resume it, or terminate it — it consults the PCB.
What Information Does the PCB Contain?
| │ Process State | READY │ |
| │ Process ID (PID) | 4527 │ |
| │ Parent PID | 1182 │ |
| │ Program Counter | 0x0040156A │ |
| │ CPU Registers | [EAX=5, EBX=0...] │ |
| │ Priority | 15 │ |
| │ Memory Pointers | [base=0x400000, │ |
| │ I/O Status | [fd0=stdin, │ |
| │ Accounting | CPU time = 2.3s │ |
| │ Start = 14 | 23:01 │ |
| │ Scheduling Info | Queue = Interactive│ |
1. Process Identification
- Process ID (PID): Unique integer identifying the process
- Parent Process ID (PPID): PID of the process that created this one
- User ID (UID): Owner of the process (for security/permissions)
- Group ID (GID): Group membership
2. Process State
Current state: New, Ready, Running, Waiting, or Terminated.
3. CPU State (Context)
The most critical section for context switching:
- Program Counter (PC): Address of the next instruction to execute
- CPU Registers: Contents of all general-purpose and special registers (accumulator, index registers, stack pointer, condition codes)
- CPU Scheduling Information: Process priority, scheduling queue pointers, other scheduling parameters
4. Memory Management Information
- Base and limit registers: Define the address space boundaries
- Page table pointer: Points to the process's page table (in paging systems)
- Segment table pointer: Points to segment table (in segmentation systems)
- Memory allocated: Total memory in use
5. I/O and Resource Information
- Open file table: List of files currently opened by the process
- I/O devices allocated: Devices assigned to this process
- Pending I/O requests: Outstanding I/O operations
6. Accounting Information
- CPU time used: Total CPU time consumed
- Wall clock time: Real time since process started
- Time limits: Maximum allowed CPU time
- Process creation time: When the process was created
PCB in Linux: The task_struct
In Linux, the PCB is implemented as the task_struct structure. It is one of the largest structures in the kernel — approximately 1.7 KB on 64-bit systems, containing over 100 fields:
// Simplified version of Linux's task_struct (actual has 600+ lines)
struct task_struct {
// State
volatile long state; // Current process state
// Identity
pid_t pid; // Process ID
pid_t tgid; // Thread Group ID
// Relationships
struct task_struct *parent; // Parent process
struct list_head children; // Child processes
// Scheduling
int prio; // Dynamic priority
int static_prio; // Static priority (nice value)
unsigned int policy; // Scheduling policy (NORMAL, FIFO, RR)
struct sched_entity se; // Scheduling entity for CFS
// Memory
struct mm_struct *mm; // Memory descriptor (page tables)
// CPU context (saved during context switch)
struct thread_struct thread; // CPU registers, FPU state
// Files
struct files_struct *files; // Open file descriptors
// Signals
struct signal_struct *signal; // Signal handling
// Accounting
u64 utime, stime; // User and system CPU time
u64 start_time; // Process start time
// Credentials
const struct cred *cred; // UID, GID, capabilities
};Role of PCB in Context Switching
The PCB is absolutely central to context switching. When the OS switches from Process A to Process B:
| Context Switch: Process A | Process B |
| Step 1 | Save A's state to A's PCB |
| Step 2 | Load B's state from B's PCB |
| Step 3 | Resume execution at B's program counter |
Without the PCB, the OS would have no way to pause a process and resume it later — all the process's state would be lost when it leaves the CPU.
Process Table
The operating system maintains a process table — essentially an array or linked list of all PCBs in the system. When you run ps in Linux or open Task Manager in Windows, you are viewing the process table.
| PID | State | Priority | CPU% | Command |
|---|---|---|---|---|
| 1 | Sleep | 20 | 0.0 | /sbin/init |
| 245 | Sleep | 20 | 0.0 | sshd |
| 1023 | Run | 20 | 12.5 | chrome |
| 1024 | Sleep | 20 | 0.0 | chrome (tab) |
| 2048 | Ready | 25 | 0.0 | gcc |
Real-World Analogy
The PCB is like a patient's medical chart in a hospital. It contains their identity (name, ID), current status (stable, critical, recovering), medical history (accounting), current medications and treatments (resources allocated), assigned doctor and ward (scheduling info), and all vital measurements (CPU state). When a doctor takes over a patient from another doctor (context switch), they read the chart to know exactly where things stand without asking the patient to start over.
Key Takeaways
- The PCB is the OS's complete record of everything about a process
- It stores process state, CPU context (registers, PC), memory info, I/O status, and accounting data
- The PCB enables context switching — saving and restoring complete process state
- In Linux, the PCB is the
task_structstructure with over 100 fields - The process table is the collection of all PCBs in the system
- PCB creation/deletion happens during process creation/termination
- The PCB is stored in kernel memory — user processes cannot directly access their own PCB
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Process Control Block (PCB).
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this Operating Systems topic.
Search Terms
operating-systems, operating systems, operating, systems, process, management, control, block
Related Operating Systems Topics