Process Control Block and Executing Process
Process Control Block (PCB) Overview
A Process Control Block (PCB) is a vital data structure maintained by the operating system (OS) for every process it manages.
Composition of PCB
The PCB must contain:
Process State: Represents the current status of the process (e.g., running, waiting, etc.).
Program Counter: Points to the address of the next instruction to be executed in the process.
Stack Pointer: Pointing to the top of the process's stack.
CPU Registers: Values of all CPU registers as they relate to the specific process currently executing.
Memory Mappings: Necessary mappings for translating virtual addresses to physical addresses for the process.
List of Open Files: Necessary for resource management during execution.
Scheduling Information: Includes details such as how much time the process has executed on the CPU and how much time it should be allocated in the future, which depends on the process's priority.
Creation and Initialization of PCB
The PCB is created at the moment the process itself is initialized.
During creation, the PCB is initialized with the following:
The program counter is set to the address of the first instruction in the process.
Updates to PCB
Certain fields within the PCB are updated in response to changes in the process state, such as:
Memory Requests: When a process requests more memory, the OS allocates the additional memory and establishes new valid virtual-to-physical memory mappings.
This update reflects the memory limits and valid virtual address regions of the process.
Such updates may not be frequent.
Other fields, such as the program counter, change more frequently:
The program counter is updated on every single instruction executed by the process.
It is impractical for the OS to update the PCB for every instruction due to performance impacts.
Role of CPU in PCB Management
The CPU maintains a dedicated register to track the current program counter for the currently executing process.
This PC Register is automatically updated by the CPU after each instruction.
The operating system is responsible for collecting and saving all pertinent information from the CPU and storing it in the PCB when the process transitions from running to a non-running state.