Process Control Block (PCB)
Introduction
我們有講到一個 CPU 可以運行多個 process 的原理便是依靠 context switch ,而為了進行 context switch,我們需要紀錄每個 process 的資訊,這樣 process 進入 CPU 開始運行 CPU 才會知道這個 process 相關的資訊
PCB 便是儲存了有關這個 process 的一切,也就是 metadata
PCB stores in Kernel Space
PCB 儲存在 kernel space
- 當 process 進入 CPU 開始執行時,會將 PCB 資訊複製到 CPU registers
- process 執行時需要 PCB 資訊,不會進入 kernel space 讀 PCB,而是直接用 CPU register 的複製
- 當 context switch 時我們便會將新的 PCB 資訊 synchronize 到 kernel space
Content
- process state
- program counter: 紀錄這個 process 下一個要執行的指令
- CPU register: 紀錄這個 process 有在用的 register
- CPU scheduling information: 紀錄這個 process 的優先級之類的資訊
- memory-management information: 紀錄這個 process 使用的記憶體資源
- accounting information:
- CPU time used: 他用了多久 CPU
- wall clock time: 從 process 開始到現在過了多久
- time limits: 這個 process 可以跑多久
- account number: 這個 process 屬於哪個使用者
- I/O status information
- 這個 process 開啟了哪些檔案
- 這個 process 在用哪些 device
- 這個 process 正在等哪些 I/O operation