CPU进程调度
5.1 基本概念
1、CPU调度也叫进程调度。
2、短程调度、中程调度、长程调度
3、CPU调度发生的情况:
(1)Switches from running to waiting state.
(2)Switches from running to ready state.
(3)Switches from waiting to ready.(例如输入输出完成)
(4)Terminates
4、非抢占式(nonpreemptive)和抢占式(preemptive)调度。前者是指让程序一直运行着,直到它自己出异常;后者允许其他程序抢占现在正在运行的程序。
5、上下文切换
5.2 调度算法的选择准则和评价
1、周转时间(turnaround time):
(1)周转时间T=完成-提交
(2)平均周转时间=ΣT/进程数
2、响应时间:从进程提出请求到首次被响应(而不是输出结果)的时间段(在分时系统环境下)
3、等待时间:进程在就绪队列中等待的时间总和
4、截止时间:
5、吞吐量:单位时间完成的进程数
6、调度算法评价标准:易于实现、开销小
5.3 调度算法
1、FCFS(first come first serve)
先来的先服务(排队)。是非抢占式的。进程得到CPU一直到运行完再运行下一个。
2、SJF(shortest job first)
在外存上的程序叫job。平均等待、平均周转时间最短的算法。
3、Priority Scheduling(优先级调度算法)
每个进程都有一个优先级,高的先运行。(Linux是0到139)。分静态优先级(优先级创建以后不会变化)和动态优先级。
问题:优先级调度算法可能会产生饥饿(Starvation),优先级低的进程可能永远得到不到运行。
4、RR(round robin)时间片轮转调度
给每个进程一个时间片(time slice)。进程排队(在ready queue),时间片用完就结束不管进程完不完都踢出去。
5多级队列调度(multilevel queue scheduling)
有多个队列,每个队列有自己的算法。
6、multilevel feedback queue scheduling
A process can move between the various queues; aging can be implemented this way.
Multilevel-feedback-queue scheduler defined by the following parameters:
1)number of queues
2)scheduling algorithms for each queue
3)method used to determine when to upgrade a process
4)method used to determine when to demote a process
5)method used to determine which queue a process will enter when that process needs service
7、高响应比优先算法(HRRN)
R=(等待时间+要求响应时间)/要求响应时间