What is a Process Control Block (PCB)?
Learn what a Process Control Block stores, how it enables context switching, and see a C struct example for OS interview prep.
Expected Interview Answer
A Process Control Block (PCB) is the kernel data structure that stores everything the OS needs to know about a process — its state, register values, memory mappings, and accounting information — so the process can be paused and resumed exactly as it was.
Every process the kernel manages has exactly one PCB, created when the process is spawned and destroyed when it terminates. It holds the process ID, current state (running, ready, blocked, terminated), saved CPU register values and program counter (used during a context switch), memory management information like page table pointers, open file descriptor tables, scheduling priority, and accounting data such as CPU time used. When a context switch happens, the kernel writes the outgoing process’s live register state into its PCB and reads the incoming process’s saved state out of its own PCB, which is exactly what lets execution resume precisely where it left off. The PCB is also where the kernel stores parent-child relationships for process trees, pending signals, and resource limits, making it the single authoritative record the scheduler, memory manager, and file system all consult about that process.
- Single source of truth the kernel uses for every subsystem touching a process
- Makes context switching possible by preserving exact CPU state
- Central to process trees, signal delivery, and resource accounting
- Foundational concept underlying scheduling, memory management, and IPC
AI Mentor Explanation
A PCB is like a player’s official team dossier that records everything needed to bring them back into a match exactly where they left off: current form, overs bowled, fielding position, and injury status. When a player is substituted off, the coaching staff update the dossier with their exact state before they leave the field. Bringing them back on later means reading that dossier and restoring them to precisely that position and condition, just as the kernel restores a process from its PCB.
Step-by-Step Explanation
Step 1
Process creation
The kernel allocates a PCB when a process is created, assigning a unique process ID and initial state.
Step 2
State updates
As the process runs, blocks, or is preempted, the kernel updates the PCB’s state field and accounting information.
Step 3
Context switch save
When switched out, the process’s live registers, program counter, and stack pointer are written into its PCB.
Step 4
Context switch restore
When switched back in, the kernel reads those saved values from the PCB to resume execution exactly where it left off.
What Interviewer Expects
- A clear list of what a PCB typically stores (state, registers, memory info, PID, accounting)
- Understanding that the PCB is what makes context switching possible
- Awareness that each process has exactly one PCB, managed by the kernel
- Ability to connect the PCB to scheduling and memory management subsystems
Common Mistakes
- Confusing the PCB with the process itself rather than its kernel metadata record
- Forgetting that the PCB holds memory management info like page table pointers
- Thinking threads do not need any per-thread equivalent of saved state
- Not knowing the PCB is what the scheduler’s ready queue actually queues references to
Best Answer (HR Friendly)
“A process control block is essentially the operating system’s file card for a running program — it stores everything needed to know exactly what that program was doing, including its current status, memory information, and exact CPU state. It’s what lets the OS pause a program and later resume it as if nothing happened, and it’s the record every other part of the system checks when it needs to know something about that process.”
Code Example
typedef enum { NEW, READY, RUNNING, BLOCKED, TERMINATED } proc_state;
struct pcb {
int pid; /* unique process identifier */
proc_state state; /* current scheduling state */
void *program_counter; /* saved instruction pointer */
long registers[16]; /* saved general-purpose registers*/
void *stack_pointer; /* saved stack pointer */
void *page_table; /* pointer to memory mappings */
int priority; /* scheduling priority */
int *open_files; /* file descriptor table */
struct pcb *parent; /* parent process, for the tree */
long cpu_time_used; /* accounting: total CPU time */
};
/* Context switch: save current process into old, restore new */
void context_switch(struct pcb *old, struct pcb *new) {
old->state = READY;
save_cpu_state(&old->program_counter, old->registers, &old->stack_pointer);
new->state = RUNNING;
load_cpu_state(new->program_counter, new->registers, new->stack_pointer);
}Follow-up Questions
- What fields in the PCB change during a context switch versus which stay fixed?
- How does the PCB relate to the process table maintained by the kernel?
- What happens to a process’s PCB after it terminates (zombie processes)?
- How would a PCB need to differ to support lightweight kernel threads?
MCQ Practice
1. What is stored in a Process Control Block?
The PCB is the kernel’s metadata record for a process, holding its state, saved CPU context, memory info, and accounting data.
2. When does the kernel write live register values into a PCB?
On a context switch, the outgoing process’s CPU registers, program counter, and stack pointer are saved into its PCB.
3. How many PCBs does a single running process have?
Each process has exactly one PCB, created at process creation and destroyed at termination.
Flash Cards
What is a Process Control Block? — The kernel data structure storing a process’s state, saved CPU context, memory mappings, and accounting info.
When is a process’s CPU state written into its PCB? — During a context switch, when the process is switched out.
How many PCBs does one process have? — Exactly one, created at process creation and freed at termination.
Name two fields commonly found in a PCB. — Process ID and current state (e.g. ready, running, blocked) — also registers, page table pointer, and priority.