How Does a Process Control Block Store Process State?

A Process Control Block (PCB) is a kernel data structure that an operating system maintains for every active process in classical computing. It serves as the central repository for everything the kernel needs to pause, resume, isolate, and manage a program, including its CPU execution state, virtual memory mappings, and open file descriptors.

Execution State and CPU Context

When the operating system switches the CPU from one process to another, it must save the exact point where the outgoing process stopped so it can resume later without data loss. The PCB stores this execution state in a dedicated context block.

  • Program Counter (PC): Holds the memory address of the next machine instruction to be executed.
  • CPU Registers: Preserves general-purpose registers, stack pointers, base pointers, and status/flag registers (such as zero, carry, or overflow flags).
  • Process Status: Tracks the current lifecycle state of the process, typically categorized as New, Ready, Running, Waiting (Blocked), or Terminated.
  • Scheduling Metadata: Records priority levels, scheduling queue pointers, and CPU time used so the scheduler can decide which process runs next.

During a context switch, the kernel copies the live hardware register values into the outgoing process's PCB, loads the saved register values from the incoming process's PCB back into the CPU, and jumps to the incoming process's saved program counter.

Memory Mappings and Address Space

Each process in a modern operating system operates in its own isolated virtual address space. Rather than storing the entire memory contents inside the PCB, the PCB stores pointers and metadata that describe how virtual addresses map to physical RAM.

  • Page Table Pointer: Points to the root of the process's page table (such as the value loaded into the CR3 register on x86 architectures), which the Memory Management Unit (MMU) uses to translate virtual addresses to physical frames.
  • Segment and Region Descriptors: Tracks the boundaries and permissions (read, write, execute) of memory segments, including the text (code), data, heap, and stack regions.
  • Base and Limit Registers: In simpler or older systems without paging, the PCB stores base and limit values to define the contiguous physical memory bounds assigned to the process.

If a process has \(N\) virtual pages, the page table maps each virtual page number to a physical frame number, allowing the hardware to enforce memory isolation between processes.

Open File Descriptors and I/O State

Processes interact with files, sockets, pipes, and devices through integer handles called file descriptors. The PCB manages these resources through a per-process file descriptor table.

  • File Descriptor Table: An array or table stored within (or referenced by) the PCB, indexed by non-negative integers (\(0\) for standard input, \(1\) for standard output, \(2\) for standard error, and higher numbers for files or sockets opened later).
  • Open File Table Pointers: Each entry in the PCB's file descriptor table points to an entry in the system-wide open file table, which tracks the current file offset (read/write position), access mode (read-only, write-only, read-write), and reference count.
  • Inode or Vnode References: The system-wide open file table entry links to the underlying filesystem inode or kernel object representing the actual file or device.

By keeping the file descriptor table inside the PCB, the operating system ensures that file offsets and access permissions remain isolated per process, while still allowing parent and child processes to share open file descriptions when appropriate.