今天早上我读到关于Linux实时调度的内容。根据罗伯特·洛夫(Robert Love)所著的《Linux系统编程》一书,有两种主要的调度方式。一种是SCHED_FIFO,先进先出,另一种是SCHED_RR,轮询。我了解了先进先出和轮询算法的工作原理。但是我们有一个系统调用,
sched_setscheduler (pid_t pid, int policy, const struct sched_parem *sp)
我们可以明确地为进程设置调度策略。因此,在某些情况下,由root运行的两个进程可能具有不同的调度策略。一个进程具有SCHED_FIFO,另一个进程具有SCHED_RR,并且具有相同的优先级。在这种情况下,哪个进程将首先被选中?FIFO类进程还是RR类进程?为什么?考虑这种情况。有三个进程A、B、C,它们都具有相同的优先级。A和B是RR类进程,C是FIFO类进程。 A和B都是可运行的(因此在某些时间间隔内交替运行)。当前A正在运行。现在C变得可运行。在这种情况下,
1. A will preempt for C, or
2. A will run until its timeslice goes zero and let C run. Or
3. A will run until its timeslice goes zero and let B run.
a) here after B runs till its timeslice becomes zero and let C run or
b) after B runs till its timeslice becomes zero and let A run again (then C will starve untill A and B finishes)