作业调度和进程调度算法
By now, you must have understood how CPU can apply different scheduling algorithms to schedule processes. Now, let us examine the advantages and disadvantages of each scheduling algorithms that we have studied so far.
到目前为止,您必须已经了解CPU如何将不同的调度算法应用于调度进程。 现在,让我们检查到目前为止研究的每种调度算法的优缺点。
先来先服务(FCFS) (First Come First Serve (FCFS))
Let's start with the Advantages:
让我们从优势开始:
FCFS algorithm doesn't include any complex logic, it just puts the process requests in a queue and executes it one by one.
FCFS算法不包含任何复杂的逻辑,它只是将流程请求放入队列中并一个接一个地执行。
Hence, FCFS is pretty simple and easy to implement.
因此,FCFS非常简单且易于实现。
Eventually, every process will get a chance to run, so starvation doesn't occur.
最终,每个进程都有机会运行,因此不会发生饥饿。
It's time for the Disadvantages:
现在是劣势的时候了:
There is no option for pre-emption of a process. If a process is started, then CPU executes the process until it ends.
无法选择先占进程。 如果启动了进程,则CPU将执行该进程,直到结束。
Because there is no pre-emption, if a process executes for a long time, the processes in the back of the queue will have to wait for a long time before they get a chance to be executed.
因为没有抢占,所以如果长时间执行某个进程,则队列后面的进程将不得不等待很长时间才能获得执行的机会。
最短工作优先(SJF) (Shortest Job First (SJF))
Starting with the Advantages: of Shortest Job First scheduling algorithm.
从优势: 最短的作业优先调度算法开始。
According to the definition, short processes are executed first and then followed by longer processes.
根据定义,先执行短流程,然后再执行长流程。
The throughput is increased because more processes can be executed in less amount of time.
由于可以在更短的时间内执行更多的处理,因此提高了吞吐量。
And the Disadvantages:
缺点:
The time taken by a process must be known by the CPU beforehand, which is not possible.
CPU必须事先知道进程所花费的时间,这是不可能的。
Longer processes will have more waiting time, eventually they'll suffer starvation.
较长的过程将有更多等待时间,最终将遭受饥饿。
Note: Preemptive Shortest Job First scheduling will have the same advantages and disadvantages as those for SJF. 注意:抢先最短作业优先调度将具有与SJF相同的优缺点。
循环赛(RR) (Round Robin (RR))
Here are some Advantages: of using the Round Robin Scheduling:
以下是一些优点:使用循环调度 :
Each process is served by the CPU for a fixed time quantum, so all processes are given the same priority.
CPU在固定的时间范围内为每个进程提供服务,因此所有进程都具有相同的优先级。
Starvation doesn't occur because for each round robin cycle, every process is given a fixed time to execute. No process is left behind.
不会发生饥饿,因为对于每个循环周期,每个进程都有固定的执行时间。 没有留下任何过程。
and here comes the Disadvantages:
缺点如下:
The throughput in RR largely depends on the choice of the length of the time quantum. If time quantum is longer than needed, it tends to exhibit the same behavior as FCFS.
RR中的吞吐量在很大程度上取决于时间量长度的选择。 如果时间量比所需时间长,则它倾向于表现出与FCFS相同的行为。
If time quantum is shorter than needed, the number of times that CPU switches from one process to another process, increases. This leads to decrease in CPU efficiency.
如果时间段短于所需时间段,则CPU从一个进程切换到另一个进程的次数将增加。 这导致CPU效率降低。
基于优先级的调度 (Priority based Scheduling)
Advantages of Priority Scheduling:
优先级调度的 优点 :
The priority of a process can be selected based on memory requirement, time requirement or user preference. For example, a high end game will have better graphics, that means the process which updates the screen in a game will have higher priority so as to achieve better graphics performance.
可以根据内存需求,时间需求或用户偏好来选择进程的优先级。 例如,高端游戏将具有更好的图形,这意味着更新游戏屏幕的过程将具有更高的优先级,从而获得更好的图形性能。
Some Disadvantages:
一些缺点:
A second scheduling algorithm is required to schedule the processes which have same priority.
需要第二种调度算法来调度具有相同优先级的进程。
In preemptive priority scheduling, a higher priority process can execute ahead of an already executing lower priority process. If lower priority process keeps waiting for higher priority processes, starvation occurs.
在抢先优先级调度中,较高优先级的过程可以在已经执行的较低优先级的过程之前执行。 如果较低优先级的进程继续等待较高优先级的进程,则会发生饥饿。
调度算法在不同情况下的使用 (Usage of Scheduling Algorithms in Different Situations)
Every scheduling algorithm has a type of a situation where it is the best choice. Let's look at different such situations:
每种调度算法都有其最佳选择的一种情况。 让我们看一下不同的情况:
情况一: (Situation 1:)
The incoming processes are short and there is no need for the processes to execute in a specific order.
传入的流程很短,不需要按特定顺序执行流程。
In this case, FCFS works best when compared to SJF and RR because the processes are short which means that no process will wait for a longer time. When each process is executed one by one, every process will be executed eventually.
在这种情况下,与SJF和RR相比,FCFS效果最好,因为进程短,这意味着没有进程会等待更长的时间。 当每个进程一个接一个地执行时,每个进程都会最终执行。
情况2: (Situation 2:)
The processes are a mix of long and short processes and the task will only be completed if all the processes are executed successfully in a given time.
流程是长流程和短流程的混合,只有在给定时间内成功执行所有流程,任务才能完成。
Round Robin scheduling works efficiently here because it does not cause starvation and also gives equal time quantum for each process.
循环调度在这里有效地工作,因为它不会导致饥饿,而且每个进程的时间量相等。
情况三: (Situation 3:)
The processes are a mix of user based and kernel based processes.
进程是基于用户的进程和基于内核的进程的混合。
Priority based scheduling works efficiently in this case because generally kernel based processes have higher priority when compared to user based processes.
在这种情况下,基于优先级的调度效率很高,因为与基于用户的进程相比,通常基于内核的进程具有更高的优先级。
For example, the scheduler itself is a kernel based process, it should run first so that it can schedule other processes.
例如,调度程序本身是基于内核的进程,因此应首先运行,以便可以调度其他进程。
翻译自: https://www.studytonight.com/operating-system/comparision-scheduling-algorithms
作业调度和进程调度算法