How does multilevel feedback queue scheduling works?
I've been reading Ritchie “Operating Systems: Incorporating UNIX and Windows” chapter 4.3 about scheduling. And I struggle to understand how this scheduling algorithm works, as my test sort of contradicts my tutors.
Here's an example question: 2 Multi-level Feedback Queues, 1 CPU
-Time quantum is 5ms for both queues
-At time t=0 process P1(8ms) arrives
-At time t=2 process P2(7ms) arrives
-At time t=6 process P3(10ms) arrives
What is the final state of the processes, queues, and CPU at time t=7?
So from my understanding this should be the outcome.
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*
Yet the answer to this question is the following:
At time 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
I'm confused, and the videos online are not helpful at all.
I think that you are misunderstanding what time=7
means. Your calculations indicate that you took it as: "What will the state of the system be after 7 intervals of time?"
What they are asking here is: "What will the state of the system be 7 milliseconds after it started running?"
And the answer to that question is:
-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
Explanation: P1 arrives at time=0 (ie 0 milliseconds after the system started) so it enters the ready queue Q1 and immediately starts running on the processor. After 5 milliseconds it is preempted and moved to Q2 where it waits to run the remaining 3 ms. At this time (5 ms after the system started) P2 has already arrived and it is waiting in Q1. So, it starts running. At 6 ms P3 arrives at Q1. So, at 7 ms after the system started: P1 is waiting at Q2 with 3 ms left. P2 is still running with 5 ms left. And P3 is waiting at Q1.
链接地址: http://www.djcxy.com/p/84838.html上一篇: 递归锁(Mutex)与非
下一篇: 多级反馈队列调度如何工作?