process state and transition
Process State
- As a process executes, it changes state
- New: The process is being created
- Running: Instructions are being executed
- Waiting: 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
Waiting: 进程正在等待某些事件发生
Ready:: 进程正在等待分配给处理器
Terminated:已终止: 进程已执行完毕
Process Scheduling
- Process scheduler selects among available processes for next execution on CPU core
- Goal -- Maximize CPU use, quickly switch processes onto CPU core
- Maintains scheduling queues of processes
- Ready queue – set of all processes residing in main memory, ready and waiting to execute
- Wait queues – set of processes waiting for an event (i.e., I/O)
- Processes migrate among the various queues
进程调度程序从可用进程中选择下一个在 CPU 内核上执行的进程
目标 -- 最大限度地利用 CPU,快速将进程切换到 CPU 内核上
维护进程调度队列
就绪队列--驻留在主内存中、准备就绪并等待执行的所有进程的集合
等待队列--等待事件(如 I/O)的进程集
进程在不同队列间迁移
CPU Switch From Process to Process
- Information associated with each process (also called task control block)
与每个进程相关的信息(也称为任务控制块)
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 via a context switch
- Context of a process represented in the PCB
- Context-switch time is pure overhead; the system does no useful work while switching
- The more complex the OS and the PCB è the longer the context switch
- Time dependent on hardware support
- Some hardware provides multiple sets of registers per CPU è multiple contexts loaded at once
当 CPU 切换到另一个进程时,系统必须保存旧进程的状态,并通过上下文切换为新进程加载保存的状态
PCB 中表示的进程上下文
上下文切换时间纯属开销;切换时系统不做任何有用的工作
操作系统和 PCB 越复杂,上下文切换的时间就越长
时间取决于硬件支持
某些硬件为每个 CPU 提供多组寄存器 同时加载多个上下文