在多编程环境中,经常会发生多个进程同时争用CPU资源的情况。如果只有一个CPU可用,则必须在两个进程之间进行选择,然后再运行。操作系统中负责选择进程的部分称为调度程序,而使用的算法称为调度算法。
多重编程的目的是最大程度地提高CPU利用率。根据判断调度算法的建议,建议诸如周转时间,响应时间,等待时间,吞吐量之类的标准。有许多CPU调度算法,其中两种是-
- 多级队列调度
- 多级反馈队列调度
多级队列(MLQ)和多级反馈队列(MLFQ)CPU调度算法之间的区别:
Multilevel queue scheduling (MLQ) | Multilevel feedback queue scheduling (MLFQ) |
---|---|
It is queue scheduling algorithm in which ready queue is partitioned into several smaller queues and processes are assigned permanently into these queues. The processes are divided on basis of their intrinsic characterstics such as memory size, priority etc. | In this algorithm, ready queue is partitoned into smaller queues on basis of CPU burst characterstics. The processes are not permanently allocated to one queue and are allowed to move between queues. |
In this algorithm queue are classified into two groups, first containing background processes and second containing foreground processes. 80% CPU time is given to foreground queue using Round Robin Algorithm and 20% time is given to background processes using First Come First Serve Algorithm. |
Here, queues are classified as higher priority queue and lower priority queues. If process takes longer time in execution it is moved to lower priority queue. Thus, this algorithm leaves I/O bound and interactive processes in higher priority queue. |
The priority is fixed in this algorithm. When all processes in one queue get executed completely then only processes in other queue are executed. Thus, starvation can occur. |
The priority for process is dynamic as process is allowed to move between queue. A process taking longer time in lower priority queue can be shifted to higher priority queue and vice versa. Thus, it prevents starvation. |
Since, processes do not move between queues, it has low scheduling overhead and is inflexible. | Since, processes are allowed to move between queues, it has high scheduling overhead and is flexible. |
1.多级队列调度(MLQ)示例:
下面根据优先级顺序列出了具有五个队列的多级队列。
- 系统进程队列
- 交互式流程队列
- 交互式编辑过程队列
- 批处理队列
- 学生进程队列
在这里,所有队列都有自己的调度算法,并且以最高优先级选择进程。然后,它被抢先或非抢先执行。在较高优先级队列都为空之前,低优先级队列中的任何进程都无法执行。
例如,如果批处理队列正在运行并且交互过程进入就绪状态,则批处理被抢占并允许执行交互过程。
2.多级反馈队列调度(MLFQ)的示例:
现在,让我们考虑具有三个队列的多级反馈队列。
- Q1表示时间周期为8毫秒的Round Robin队列。
- Q2表示时间周期为16毫秒的Round Robin队列。
- 问题Q3:先到先服务队列。
现在,当进程进入Q1时,它被允许执行,如果它在8毫秒内未完成,则转移到Q2并接收16毫秒。如果它在16秒内未完成,它将再次抢占到Q3。以这种方式,在该方案中进行调度。