Start here
/proc, debuggers) read fields that ultimately come from here (directly or via stable summaries).Process Control Block (PCB)
The PCB aggregates identity (PID, parent pointers), scheduling (priority, runqueue linkage), memory (pointer to address-space metadata), files (descriptor table), and signals (mask, disposition, pending bitmap). On Linux, think of task_struct plus structures it points to (mm_struct, files_struct, …).
By the end of this page you should be able to
- Name three categories of fields stored in the PCB.
- Explain why not every PCB field is saved on every context switch.
- Relate `/proc/[pid]/status` to PCB concepts.
Operating systems · Processes
Process control block (PCB)
Process Control Block = kernel’s struct for a process
TL;DR
The PCB (Linux `task_struct` + related structs) stores everything the kernel must preserve across preemption: scheduling, memory map pointers, file table, signals, credentials, accounting, and cgroup links, context switch = serialize relevant subset of this state.
Summary
Think of the PCB as the save game for a process: incomplete or corrupted state leads to crashes or privilege bugs. Reading kernel sources for `task_struct` is advanced but clarifies why certain operations are expensive.
Deeper narrative
The PCB is the anchor for everything debuggable: `/proc/[pid]/status`, `sched`, `maps`, `fd`. When you “pause” a container, you are freezing tasks whose PCB linkage still exists in the global process table (subject to namespaces).
Mechanism (step by step)
Identity & hierarchy
PID/TGID, parent pointers, cgroup membership, namespace links.
CPU scheduling fields
Priority, vruntime, runqueue node, migration constraints.
Memory context
Pointer to `mm_struct`, RSS stats, lazy FPU state.
Files & signals
File descriptor table, signal mask/disposition, pending list.
Key insights
Splitting hot and cold fields
Pointer validity rules
Namespace pointers
Security fields
Did you know?
Common pitfalls
Reading PCB fields without locks
Race with concurrent exec or multithreaded mutation, use official APIs or `ptrace` stop states.
Huge PCB == slow context switch?
Hot subset is per-CPU or lazily switched (FPU); not every field saved each time.
Glossary
mm_struct
files_struct
Runqueue node
Interview follow-ups
- Which PCB fields must change on `execve` vs `fork`?
- How does `clone` reuse PCB layout for threads?
- Where is pending signal bitmap stored relative to the thread?
Callouts
Interview tip
If asked “what is stored in PCB?”, group answer: identity, CPU state snapshot location, memory, files, signals, security, accounting.
Walkthrough & deep dive
Left: practical “how would I use this?” threads. Right: slower, code-leaning explanations, open one panel at a time so the page does not feel like a wall of sameness.
Walkthrough
Memory exercise
Deep dive
Where are saved registers?
On syscall/interrupt entry, CPU state is pushed onto the per-thread kernel stack; `thread_struct` may hold additional persistent registers for context switch.
Kernel doc pointer
Read: Documentation/sched/* and include/linux/sched.h comments (online mirrors) for field intent.
Self-check
1The PCB primarily lives in…
2Sharing `mm_struct` implies threads share…
3File descriptors are tracked via…