📌  相关文章
📜  最短作业优先(SJF)与轮循(RR)调度算法之间的差异

📅  最后修改于: 2021-08-25 10:43:17             🧑  作者: Mango

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

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

笔记 –
如果两个进程的突发时间相同,则使用FCFS断开连接,即首先处理最先到达的进程。

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

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

该算法的主要优点是,所有进程都一个接一个地执行,这不会导致进程出现饥饿或等待进程等待很长时间才能执行。最短作业优先(SJF)与轮循(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.