问题
有多个就绪的进程或线程,哪一个应该先执行?
When to schedule
- Process creates
- Process exits
- Process blocks on IO
- IO interrupts
How to schedule
Scheduling Algorithm
相关概念
Throughput(吞吐量)
- 单位时间内执行的任务数
Turnaround(周转时间)
- 提交到结束所需时间
Average Turnaround time
- 平均数
Waiting time
- 在ready queue里等待的时间
Response time
- 提交到第一次获得响应的时间,不同于周转时间
CPU utilization
Categories
Preemptive & Non-preemptive
- 抢占式调度算法涉及到优先级
Batch
FCFS
Fist come First serve
SJF
Shortest job first
- 非抢占式
- 抢占式
Interactive System
Round-Robin Scheduling
轮转调度
相关概念
- quantum
特点
- 平均周转时间大,response time小
一体两面
- quantum太大,response time太大
- quantum太小,进程切换频繁
Priority Scheduling
- 先用轮转调度执行优先级最高的,再执行优先级低的
Multiple Queues
多级队列
- 类似Priority Scheduling,每层调度算法可以不一样
- 计算起来最复杂,最爱考
Guaranteed Scheduling
Lottery Scheduling
Fair Share Scheduling
- 更公平的Guaranteed Scheduling
Real time
Real time Scheduling
概念
- 有一个进程集合,里面的进程对时间都有要求,对这组进程的调度就叫实时调度
hard real time
- 不可错过的deadline
soft real time
- 有deadline,但是错过就错过了吧
Priority inversion
概念
- 低优先级的进程阻塞了高优先级的进程
栗子
- 低优先级的进程进入了关键区,突然切到了高优先级进程,高优先级也要访问关键区,结果被阻塞
