在BACH的一书《UNIX操作系统设计》里面看到如下关于linux进程调度的算法,不理解,希望高手解惑,谢谢!
algorithm:schedule_process
{
while(no process picked to execute)
{
for(every process on runqueue)
picked highest priority process that is load in memory;
if(no process eligible to excute)
idle the machine ;
/*interrupt takes machine out of idle state*/
}
remove chosen process from run queue ;
switch context to that of chosen process ,resum its execution ;
}
Operating system process scheduler implementations
The algorithm used may be as simple as round-robin in which each process is given equal time (for instance 1 ms, usually between 1 ms and 100 ms) in a cycling list. So, process A executes for 1 ms, then process B, then process C, then back to process A.
More advanced algorithms take into account process priority, or the importance of the process. This allows some processes to use more time than other processes. The kernel always uses whatever resources it needs to ensure proper functioning of the system, and so can be said to have infinite priority. In SMP(symmetric multiprocessing) systems, processor affinity is considered to increase overall system performance, even if it may cause a process itself to run more slowly. This generally improves performance by reducing cache thrashing.
这是一段伪码,翻译过来就好懂喽
大致意思就是
遍历运行队列从中挑选“合适”的进程,一般按照优先级和时间片选择进程,如果存在满足条件的进程,则退出查询循环,从运行队列上摘此进程(其实就是删除链表结点),然后切换进程上下文。如果不存在满足条件的进程(即运行队列空),则执行idle(就是空循环)