Process State

States

new

此時 process 剛被建立,但還沒有進入 scheduler。OS 正在初始化 PCB,但尚未分配實際執行資源

ready

Process 已經準備好執行,所有需要的資源都已經就位只差 CPU

running

Process 正在被 CPU 執行

waiting/blocked

Process 正在等待某個外部事件發生,像是 disk I/O、網路封包到達。這時 process 所需的資源還沒準備好,就算給他 CPU 也沒用

terminated

Process 執行完畢,OS 回收資源,process 進入 zombie process 狀態等待回收

Transitions

admitted

  • 權限檢查:這個使用者有沒有權限執行這支程式?
  • 資源可用性確認:系統有沒有足夠的記憶體可以分配?
  • 實際資源分配:page table 建立、記憶體空間分配、程式碼載入等
  • 全部完成後把 process 丟到 ready state

scheduler dispatch

scheduler 選擇 process 後將 CPU register 設定成他的狀態並開始執行

interrupt

CPU 計時器時間到了,OS 強制叫停 process 並進行 context switch

I/O or event wait

Process 主動呼叫了需要等待的 system call。此時 CPU 不用 busy-waiting 而是讓 OS 把它丟去 waiting state

I/O or event completion

等到想要的資源了回去 ready state

exit

process 執行完畢