TutorialsOperating Systems
Core CS

Process Control Block

A Process Control Block (PCB), also known as a Task Control Block, is a fundamental kernel data structure used by an operating system to track and manage the execution state of a specific process. Whenever a process is created, the OS allocates a dedicated PCB that acts as its identification profile, storing all execution metadata—such as the program counter, CPU registers, process state, and memory allocations. When the OS performs a context switch to swap out a running process, it serializes the process's current hardware state into its PCB, allowing the process to resume later exactly where it left off without losing computation progress.

<p></p><h2><!--StartFragment--></h2><h2><b>&nbsp;Definition</b></h2><p>In modern multitasking operating systems, a process is dynamic and alternates between active CPU computation, waiting for I/O operations, and sitting in ready queues. The operating system cannot maintain all active processes inside physical CPU registers simultaneously. The <b>PCB serves as an in-memory repository</b> residing in protected kernel space that completely encapsulates a process's hardware and software execution contexts. It is the central mechanism through which schedulers prioritize tasks, memory management units (MMUs) enforce isolation, and resource managers track open handles and I/O devices.</p><h3><b><br></b><b>Core Components of a PCB</b></h3><ul><li><b style="font-family:Inter, ui-sans-serif, system-ui, -apple-system,">Process Identifier (PID):</b><span style="color:rgb(0, 0, 0)"> A unique integer assigned by the OS to identify the process across the system, alongside its Parent Process ID (PPID).</span></li><li><p><b>Process State:</b> The current operational stage of the process, such as <code>New</code>, <code>Ready</code>, <code>Running</code>, <code>Waiting</code>/<code>Blocked</code>, or <code>Terminated</code>.</p></li><li><p><b>Program Counter (PC):</b> The memory address pointing to the next machine instruction the CPU must fetch and execute for this process.</p></li><li><p><b>CPU Registers:</b> A snapshot of processor registers—including accumulators, base/index registers, stack pointers (<code>ESP</code>/<code>RSP</code>), and flags/condition codes—saved during an interrupt or context switch.</p></li><li><p><b>CPU Scheduling Information:</b> Attributes required by the scheduler to allocate CPU time, such as priority levels, scheduling algorithm queue pointers, and quantum/tick counters.</p></li><li><p><b>Memory Management Information:</b> Page tables, segment tables, base and limit registers, and virtual address map pointers defining the process's allocated address space.</p></li><li><p><b>Accounting &amp; Diagnostic Info:</b> Metrics tracked for resource billing and optimization, including total CPU execution time consumed, clock limits, and user credentials.</p></li><li><p><b>I/O Status Information:</b> Pointers and descriptors for allocated devices, pending I/O requests, and the file descriptor table (mapping open files and network sockets).</p></li></ul><h3><b>Role in Context Switching</b></h3><p>&nbsp;When the CPU switches execution from Process A to Process B:</p><ol><li><p>The kernel receives a timer interrupt or system call.</p></li><li><p>The current register state, program counter, and stack pointer are copied directly from the CPU hardware into <b>PCB_A</b>.</p></li><li><p>Process A's state updates from <code>Running</code> to <code>Ready</code> (or <code>Waiting</code>).</p></li><li><p>The scheduler selects Process B and locates <b>PCB_B</b>.</p></li><li><p>The CPU registers and program counter are restored from <b>PCB_B</b> into the hardware registers.</p></li><li><p>The MMU updates page table pointers to Process B's memory boundaries, and execution resumes.</p><!--EndFragment--></li></ol><!--EndFragment--><p></p>