Operating Systems Process state g As a process executes, it changes state H new: The process is being created H running: Instructions are being executed H waiting(blocked) The process is waiting for some event to occur w ready: The process is waiting to be assigned to a processor. E terminated: The process has finished execution Gao Haichang, Software School, Xidian University 13
Operating Systems Gao Haichang , Software School, Xidian University 13 Process State As a process executes, it changes state new: The process is being created. running: Instructions are being executed. waiting (blocked): The process is waiting for some event to occur. ready: The process is waiting to be assigned to a processor. terminated: The process has finished execution
Operating Systems Diagram of Process State new admitted interrupt exit terminated ready running scheduler dispatch 1/O or event completion l/o or event wait waiting Gao Haichang, Software School, Xidian University 14
Operating Systems Gao Haichang , Software School, Xidian University 14 Diagram of Process State
Operating Systems When to switch a process e Clock interrupt H process has executed for the maximum allowable time slice e y interrupt G Memory fault memory address is in virtual memory so it must be brought into main memory G Trap H error occurred H may cause process to be moved to exit state 矿 Supervisor call管理程序调用 A such as file open Gao Haichang, Software School, Xidian University 15
Operating Systems Gao Haichang , Software School, Xidian University 15 When to Switch a Process Clock interrupt process has executed for the maximum allowable time slice I/O interrupt Memory fault memory address is in virtual memory so it must be brought into main memory Trap error occurred may cause process to be moved to Exit state Supervisor call 管理程序调用 such as file open
Operating Systems CPU Switch From Process to Process process P operating system process Pt interrupt or system call executing save state into PCB reload state from PCB, idle interrupt or system call executing save state into PCB reload state from PCBo executing Gao Haichang, Software School, Xidian University 16
Operating Systems Gao Haichang , Software School, Xidian University 16 CPU Switch From Process to Process
Operating Systems Context switch上下文切换 c When cpu switches to another process, the system must save the state of the old process and load the saved state for the new process. c Context represented in PCB of a process, include CPU registers pI rocess state memory-management information G Context- switch time is overhead(额外负担; the system does no useful work while switching. g Time dependent on hardware support Gao Haichang, Software School, Xidian University 17
Operating Systems Gao Haichang , Software School, Xidian University 17 Context Switch 上下文切换 When CPU switches to another process, the system must save the state of the old process and load the saved state for the new process. Context represented in PCB of a process,include -CPU registers -process state -memory-management information Context-switch time is overhead (额外负担); the system does no useful work while switching. Time dependent on hardware support