📌  相关文章
📜  最短作业优先 (SJF) 和循环 (RR) 调度算法之间的区别

📅  最后修改于: 2021-09-28 09:53:38             🧑  作者: Mango

1.最短作业优先(SJF):
最短作业优先 (SJF) 调度算法基于进程的突发时间。这些进程根据它们的突发时间被放入就绪队列。在该算法中,最先处理突发时间最少的进程。仅比较在该时间之前存在或已经到达的那些进程的突发时间。它本质上也是非抢占式的。它的抢占式版本称为最短剩余时间优先 (SRTF) 算法。

该算法的主要优点是它为给定的一组进程提供了最短的等待时间,从而减少了平均等待时间。该算法的缺点是系统可能永远不会处理长进程,并且可能会在队列中停留很长时间,导致进程饥饿。

笔记 –
如果两个进程具有相同的突发时间,则使用 FCFS 打破平局,即首先处理最先到达的进程。

2.循环(RR):
循环 (RR) 调度算法是专门为分时系统设计的。进程被放入就绪队列中,在这种情况下它是一个循环队列。在这种情况下,定义了一个称为时间量的小时间单位。该算法从队列中选择第一个进程并在时间片定义的时间内执行它。如果进程的突发时间小于时间片,则 CPU 执行下一个进程,但如果它的突发时间大于时间片,则该过程被中断,并在相同的时间片内执行下一个进程。如果进程被中断,则会发生上下文切换,并将进程放回队列的尾部。它本质上是先发制人的。

该算法主要依赖于时间量程。非常大的时间量使 RR 与 FCFS 相同,而非常小的时间量会导致开销,因为上下文切换将在非常小的间隔后一次又一次地发生。

该算法的主要优点是所有进程都一个接一个执行,这不会导致进程饥饿或进程等待很长时间才能执行。 Shortest Job First(SJF)和Round-Robin(RR)调度算法的区别如下:

Shortest Job First (SJF) Round-Robin (RR)
Shortest Job First (SJF) executes the processes based upon their burst time i.e. in ascending order of their burst times. Round-Robin (RR) executes the processes based upon the time quantum defined i.e. each process is executed for a fixed amount of time.
SJF is also non-preemptive but its preemptive version is also there called Shortest Remaining Time First (SRTF) algorithm. Round-Robin (RR) is preemptive in nature.
The average waiting time for given set of processes is minimum. The average waiting time for given set of processes is quite small and depends on the time quantum.
The real difficulty with SJF is knowing the length of the next CPU request or burst. It is quite easy to implement RR.
A long process may never get executed and the system may keep executing the short processes. Each process is executed and every user feels that his work is being done as the CPU gives equal amount of time to each process.
In case of SJF, elapsed time should be recorded, results in more overhead on the processor. In case of RR, if the time quantum is very small then context switch takes place again and again after very short intervals of time which leads to overhead.