ProcessControlBlock.md (1814B)
1 # Process Control Block (PCB) 2 3 **Source:** CS 6200 4 5 **Chapter:** P2L1 6 7 **Definition:** The process control block is a data structure maintained by the operating system that contains process state. There is one PCB for each process. 8 9 ## Includes 10 11 - Process state 12 - Process number 13 - Program counter 14 - Registers 15 - Things like the program counter are automatically updated by the CPU, but the OS must ensure it knows which registers a process is using so it can switch between processes without losing data. 16 - Memory limits 17 - Open files 18 - Priority 19 - Signal mask 20 - CPU scheduling info 21 - ... 22 23 The PCB is created when a process is started, and during runtime certain fields may be updated. 24 25 ### Hard and Soft Process State 26 27 When using multiple kernel level threads for a singular process, there is hard process state and light process state in the PCB. The hard process state is state information relevant for all threads, like the virtual address mapping. There is also soft state, like the registers for a given thread, which is only applicable to a specific thread. 28 29 By using multiple data structures to represent the PCB, they are easier to share between threads and they are easier to manage from user-level threading libraries, which only have to upade a smaller portion of the state. 30 31 Most operating systems today use multiple data structures to represent the PCB. 32 33 ## Runtime 34 35 Assume process P1 is running and P2 is idle. The CPU registers are currently populated with data from P1. When the OS decides to interrupt P1's execution it performs the following operations: 36 37 1. Set P1 as idle 38 - OS interrupts the process to stop subsequent instruction executions 39 2. Saves data from registers to P1's PCB 40 3. Restores registers based on P2's PCB 41 42 This switch is called [context switching](ContextSwitching.md).