多级反馈队列调度如何工作?

时间:2017-04-29 01:48:02

标签: operating-system queue scheduling

我一直在阅读Ritchie“操作系统:合并UNIX和Windows”第4.3章关于日程安排。我很难理解这种调度算法是如何工作的,因为我的测试与我的导师相矛盾。

以下是一个示例问题: 2个多级反馈队列,1个CPU

 T0 => Q1(P1(8ms) Running), Q()
 T1 => Q1(), Q2(P1(3ms) Ready) *preemptively moved to Q2*
 T2 => Q1(P2(7ms) Running), Q2(P1(3ms) Ready)
 T3 => Q1(), Q2(P2(2ms) Ready, P1(3ms) Ready) *preemptively moved to Q2*
 T4 => Q1(), Q2(P2(2ms) Ready, P1(3ms) Running)
 T5 => Q1(), Q2(P2(2ms) Ready) *P1(3ms) executed for 3ms and terminated*
 T6 => Q1(P3(10ms), Ready), Q2(P2(2ms) Running)
 T7 => Q1(P3(10ms), Running), Q2() *P2(2ms) executed for 2ms and terminated*

流程的最终状态是什么, 队列和CPU在时间t = 7?

所以根据我的理解,这应该是结果。

-P1 has been executed for 5ms and it is in the READY state of the 2nd queue
-P2 has been executed for 2ms and it is in the RUNNING state
-P3 has arrived and it is in the READY state of the 1st queue

然而,这个问题的答案如下:

在时间t = 7:

Date.created_at.try(:strftime, ("%B %e, %Y"))

我很困惑,在线视频根本没用。

1 个答案:

答案 0 :(得分:1)

我认为你误解了time=7的含义。您的计算表明您将其视为:&#34;系统状态在7 <间隔时间之后会是什么状态?&#34;

他们在这里问的是:&#34;系统状态在开始运行后 7毫秒会是什么?&#34;

这个问题的答案是:

-P1 has been executed for 5ms and it is in the READY state of the 2nd queue
-P2 has been executed for 2ms and it is in the RUNNING state
-P3 has arrived and it is in the READY state of the 1st queue

说明: P1到达时间= 0(即系统启动后0毫秒),因此它进入就绪队列Q1并立即开始在处理器上运行。在5毫秒后,它被抢占并移动到Q2,等待运行剩余的3毫秒。此时(系统启动后5 ms)P2已经到达并且在Q1中等待。所以,它开始运行。在6毫秒时,P3到达Q1。因此,在系统启动后7 ms :P1在Q2处等待,还剩3 ms。 P2仍在运行,还剩5毫秒。 P3正在等待Q1。