特殊情况调度 [英] Special case scheduling

查看:24
本文介绍了特殊情况调度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题来了.在研究进程调度时,我遇到了两个看似矛盾的例子,我无法理解.

So here's the question. While studying about process scheduling I came across two seemingly contradictory examples I just can't get my head around.

例如在优先级非抢占式调度算法中,总是选择优先级最高的进程下一个运行,一旦运行,进程只能自愿放弃其CPU时间,即没有其他进程可以运行直到当前运行的进程完成.看来这本书提出的解决方案是,如果一个进程的结束和新的高优先级进程的到来同时发生,那么新的高优先级进程将被添加到就绪队列中,然后由接下来要运行的调度程序.

The problem arises if for instance in the priority non-preemptive scheduling algorithm which always chooses the process with the highest priority to be run next and once running, process can only volontarily give up its CPU time, that is no other process can run until the currently running process finishes. It seems that what the solution the book proposes is that if both end of one process and arrival of the new high-priority process occur at the same time, the new high-priority process will be added to the ready queue and then chosen by the scheduler to be run next.

但是在循环算法的另一个例子中,如果就绪队列中只有一个进程并且它当前正在运行,如果同时它的时间片已经过去并且新进程说它准备好了,那么似乎提出的解决方法是先调度,这样当前运行的进程会继续运行,同时新的进程会加入队列.

But in the other example in Round-robin algorithm, if there is only one process in the ready queue and it is currently running, if at the same time its quantum elapses and new process says its ready, it seems that the proposed solution is that the scheduling will be done first, so the currently running process will continue to run while the new process will be added to the queue.

如果有人向我澄清这一点,我将不胜感激,因为我从其他一些帖子中知道,对于队列中的单个进程,上下文切换不会在循环中发生,但总的来说,调度是在添加新进程之前完成的吗?进程排队.

I'd be grateful if someone clarified this to me, because I know from some other post that context switch does not occur in round robin for single process in queue, but is it true in general that scheduling is done before adding new process to queue.

推荐答案

我从你的描述中得到的是:

What I get from you description is:

时间 0:

进程 1 开始使用它的时间片,例如5 个单位.

Process 1 starts using its time slice, e.g. 5 units.

时间 5:

进程 2 到达.进程 1 用完它的时间片并得到补充.

Process 2 arrives. Process 1 used up its time slice and is replenished.

循环调度程序通过选择剩余时间的下一个进程来检查就绪队列.在时间 0,您的就绪队列如下所示:

A round robin scheduler checks the ready queue by selecting the next process with time left. At time 0 your ready queue looks like this:

P1

在时间 5:

P1 转到 P1 -> P2

P1 going over to P1 -> P2

Tanenbaum 在现代操作系统中写道:当一个进程用完它的时间片时,它会在最后排队.所以发生的情况是,P1 在 P2 第一次入队之前再次入队.这节省了从 P1 到 P2 并返回到 P1 的额外上下文切换.如果要先运行 P2,则可以使用优先级基础循环.

Tanenbaum writes in Modern Operating Systems: When a process used up it's time slice, it is enqueued at the end. So what happens is, that P1 is enqueued again before P2 is enqueued for the first time. This saves an additional context switch from P1 to P2 and back to P1. If you want P2 to be run first, then you can use priority base round robin.

这篇关于特殊情况调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆