การจัดตาราง
แนะนำใหม่ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| FCFS/ˌef siː ef ˈes/ | 先来先服务 (FCFS) |
| SJF/ˌes dʒeɪ ˈef/ | 短作业优先 (SJF) |
| round robin/raʊnd ˈrɒbɪn/ | 时间片轮转 (round robin) |
| Gantt chart/ɡænt tʃɑːt/ | 甘特图 (Gantt chart) |
| Turnaround time/ˈtɜːnəraʊnd taɪm/ | Finish − arrival. |
| waiting time/ˈweɪtɪŋ taɪm/ | เวลาในการรอ |
| convoy effect/ˈkɒnvɔɪ ɪˈfekt/ | short jobs wait behind one long job in first-come, first-served scheduling |
| response time/rɪˈspɒns taɪm/ | the time from a request arriving until the first response begins |
| Priority scheduling/praɪˈɒrɪti ˈʃedjuːlɪŋ/ | running the ready process with the highest priority first |
| aging/ˈeɪdʒɪŋ/ | slowly raising the priority of waiting processes so that none starves |
| multilevel feedback queue/ˌmʌltɪˈlevl ˈfiːdbæk kjuː/ | a scheduler with several priority queues that moves processes between them according to how they behave |
| SRTF/ˌes ɑː tiː ˈef/ | Shortest remaining time first: preemptive shortest-job-first scheduling that always runs the job with the least work left. |
| Exponential averaging/ˌekspəˈnenʃl ˈævrɪdʒɪŋ/ | Predicting the next value as a weighted mix of the latest observation and the previous prediction, so older values fade geometrically. |
Three policies, one job set
- The course set: bursts P1 = 7, P2 = 4, P3 = 1, P4 = 4, all arriving at time 0. FCFS 先来先服务 (first come, first served) runs them in order; SJF 短作业优先 (shortest job first) runs the shortest next; round robin 时间片轮转 (quantum 2) gives each job a turn in a cycle.
- A Gantt chart 甘特图 shows who ran when.

For the course set (7, 4, 1, 4 at time 0), the policy with the lowest average turnaround is —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
SJF averages 7.75 against FCFS 11.5 and RR 11.25.
The formula, the numbers
- Turnaround time 周转时间 = finish − arrival; waiting time 等待时间 = turnaround − burst. FCFS finishes at $7, 11, 12, 16$: average turnaround $11.5$. SJF (P3, P2, P4, P1) finishes at $1, 5, 9, 16$: average $7.75$.
- RR ($q = 2$) runs P1 P1 | P2 P2 | P3 | P4 P4 | P1 P1 | P2 P2 | P4 P4 | P1 P1 | P1. P3 finishes at $5$, P2 at $11$, P4 at $13$ and P1 at $16$: average $11.25$. Same jobs, three different answers.
Under FCFS the set finishes at —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
First-come first-served: cumulative bursts 7, 11, 12, 16.
Convoys and quanta
- The convoy effect 护航效应: under FCFS the 7-unit job comes first, and P3 waits $11$ units for $1$ unit of work. This is how FCFS fails interactive users.
- Choosing the quantum: a large $q$ turns into FCFS; a tiny $q$ spends the CPU on switching. A $1$ µs switch wastes $0.05\%$ in a $2$ ms quantum but $5\%$ in a $20$ µs quantum. Switches are work, not progress.
A 1 µs switch in a 20 µs quantum wastes —
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
1 µs / 20 µs = 5% — quanta too small spend the CPU on switching.
Round robin with a quantum longer than every burst behaves exactly like FCFS.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Every job finishes inside its first slice, so jobs run once each, in arrival order: the FCFS schedule, with FCFS's convoy effect.
Response time and priorities
- Interactive users feel the response time 响应时间: first run minus arrival. On the course set, FCFS gives $0, 7, 11, 12$, an average of $7.5$; SJF gives $3.75$; round robin with $q = 2$ gives $0, 2, 4, 5$, only $2.75$. RR loses on turnaround but wins on response.
| Course set | Avg turnaround | Avg waiting | Avg response |
|---|---|---|---|
| FCFS | 11.5 | 7.5 | 7.5 |
| SJF | 7.75 | 3.75 | 3.75 |
| RR, $q = 2$ | 11.25 | 7.25 | 2.75 |
- No policy wins every column: SJF is best for finishing, round robin for first response.
- Priority scheduling 优先级调度 can starve low-priority jobs, so aging 老化 raises a job's priority while it waits.
- A multilevel feedback queue 多级反馈队列 starts every job at high priority and moves down those that use their whole quantum. Short interactive jobs stay quick without the OS knowing burst lengths in advance.
For the course set under FCFS (P1 = 7, P2 = 4, P3 = 1, P4 = 4, all at time 0), what is the average waiting time?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Waits are 0, 7, 11 and 12, which average 30 / 4 = 7.5.
Under SJF on the same set, what is the average waiting time?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Order P3, P2, P4, P1: waits 0, 1, 5 and 9, average 15 / 4 = 3.75.
Preemptive SJF: shortest remaining time
- Now let jobs arrive over time: P1 = 7 at 0, P2 = 4 at 2, P3 = 1 at 4, P4 = 4 at 5. SRTF 最短剩余时间优先 always runs the job with the least work left, and interrupts the current job when a shorter one arrives.
- The schedule is P1 0–2, P2 2–4, P3 4–5, P2 5–7, P4 7–11, P1 11–16. The waiting times are 9, 1, 0 and 2: an average of $\mathbf{3}$, the lowest any policy can reach on this set.
SRTF waiting times 9, 1, 0 and 2: average waiting time?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
$(9 + 1 + 0 + 2)/4 = 3$.
Worked example: predicting the next burst
- SJF needs burst lengths before they happen. Exponential averaging 指数平均 predicts $\tau_{n+1} = \alpha t_n + (1 - \alpha)\tau_n$.
- With $\alpha = 0.5$, a first guess of 10 and bursts 6, 4, 6, 4, the predictions are 8, 6, 6 and $\mathbf{5}$. Recent bursts count most, and the weight of older ones halves each time.
$\alpha = 0.5$, $\tau_0 = 10$, bursts 6, 4, 6, 4: the prediction after the fourth burst?
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
8, then 6, then 6, then $0.5 \times 4 + 0.5 \times 6 = 5$.
SJF can be run exactly because the OS knows each burst length in advance.
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
It predicts them, typically by exponential averaging of past bursts.
Marks that slip away
- Waiting time as finish minus arrival. That is turnaround; waiting is turnaround minus burst.
- SJF as if bursts were known. It gives the lowest average waiting time, but the OS has to predict burst lengths.
- A tiny quantum for responsiveness. With a $1$ µs switch, a $20$ µs quantum wastes $5\%$ of the CPU.
Recap
- Turnaround = finish − arrival; waiting = turnaround − burst; response = first run − arrival.
- Course set average turnaround: FCFS $11.5$, SJF $7.75$, RR ($q = 2$) $11.25$.
- Large quanta drift to FCFS; tiny quanta waste the CPU on switches.
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้