4. 排程基本上分成兩大類…
• non-preemptive scheduling
a) process取得CPU主控權後一定會做好做滿才離開
b) 對所有的process公平,Response time可以預期,但average
waiting time比較高
c) e.g. FCFS、non-preemptive SJF、RR、non-preemptive priority
scheduling
• preemptive scheduling
a) CPU控制權允許較高優先權的process先做(可能會被中斷)
b) 即時/交談系統適用,但可能會造成starvation、context switch 變多
c) e.g. preemptive SJF、priority scheduling
4
5. First Come First Serve (FCFS)
• 先來的先做,最直覺的做法,但很有可能會發生Convey effect
• Convey effect (護衛效應):長的CPU burst process都擠在前面
先做,導致average waiting time變長。
5
47. P1
Rate Monotonic (2/5)
47
0
P2到達
P1 CPU time = 10-4=6
當前Process:P1、P2
P2 CPU time只需要3所以P2先做1,t=5時,P3到達
P2 CPU time仍然是最小所以就繼續做直到完成為止
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 6 24 0
P2 3 18 4
P3 10 19 5
P2 P2
P3到達
End
75
48. P1
Rate Monotonic (3/5)
48
0
P2到達
P2 CPU time = 3-3=0
當前Process:P1、P3
P1 CPU time只需要6<10,所以讓P1先做完
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 6 24 0
P2 0 18 4
P3 10 19 5
P2 P2
P3到達
End
75
P1
End
13
49. P1
Rate Monotonic (4/5)
49
0
P2到達
P1 CPU time = 6-6=0
當前Process:P3
所以讓P3完成
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 0 24 0
P2 0 18 4
P3 10 19 5
P2 P2
P3到達
End
75
P1
End
13
P3
End
23
50. P1
Rate Monotonic (5/5)
50
0
P2到達
P3 CPU time = 10-10=0
考慮各Process的執行時間:
P1 = 13 < 24
P2 = 7 < 18
P3 = 23 > 19 (超出時間)
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 0 24 0
P2 0 18 4
P3 0 19 5
P2 P2
P3到達
End
75
P1
End
13
P3
End
23
51. P1
Earliest Deadline First (1/5)
51
0
P2到達
當前Process:P1
所以P1先做4,P2到達
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 10 24 0
P2 3 18 4
P3 10 19 5
52. P1
Earliest Deadline First (2/5)
52
0
P2到達
P1 CPU time = 10-4=6
當前Process:P1、P2
P2 deadline=18<24所以P2先做1,t=5時,P3到達
P2 deadline=18<19仍然是最早所以就繼續做直到完成為止
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 6 24 0
P2 3 18 4
P3 10 19 5
P2 P2
P3到達
End
75
53. P1
Earliest Deadline First (3/5)
53
0
P2到達
P2 CPU time = 3-3=0
當前Process:P1、P3
P3 deadline=19<24,所以P3先做完
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 6 24 0
P2 0 18 4
P3 10 19 5
P2 P2
P3到達
End
75
P3
17
End
54. P1
Earliest Deadline First (4/5)
54
0
P2到達
P3 CPU time = 10-10=0
當前Process:P1
所以輪到P1做完
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 6 24 0
P2 0 18 4
P3 0 19 5
P2 P2
P3到達
End
75
P3
17
End
P1
End
23
55. P1
Earliest Deadline First (5/5)
55
0
P2到達
P1 CPU time = 6-6=0
考慮各Process的執行時間:
P1 = 23 < 24
P2 = 7 < 18
P3 = 17 < 19
4
Process
ID
CPU
time
Deadline
Arrival
Time
P1 0 24 0
P2 0 18 4
P3 0 19 5
P2 P2
P3到達
End
75
P3
17
End
P1
End
23