📜  FCFS 和 SJF CPU 调度算法的区别

📅  最后修改于: 2021-09-27 14:42:41             🧑  作者: Mango

1. 先到先得(FCFS):
先到先得 (FCFS) 是最简单的算法类型。它是一种非抢占式算法,即进程一旦开始执行就不能被中断。 FCFS 是在 FIFO 队列的帮助下实现的。进程按照到达时间的顺序放入就绪队列。首先到达的进程成为队列的头部,而其他随后到达的进程被添加到队列的尾部。在先来先服务 (FCFS) 算法中,先到达的进程在 CPU 空闲时首先发送给 CPU 执行。

这种算法的主要缺点是平均等待时间通常很长。这也导致了车队效应。这会导致较低的设备或 CPU 利用率以及较低的效率。

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

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

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

先来先服务(FCFS)和最短作业优先(SJF)调度算法的区别如下:

First Come First Served (FCFS) Shortest Job First (SJF)
First Come First Served (FCFS) executes the processes in the order in which they arrive i.e. the process that arrives first is executed first. Shortest Job First (SJF) executes the processes based upon their burst time i.e. in ascending order of their burst times.
FCFS is non preemptive in nature. SJF is also non-preemptive but its preemptive version is also there called Shortest Remaining Time First (SRTF) algorithm.
FCFS results in quite long waiting time for the processes and thus increases average waiting time. The average waiting time for given set of processes is minimum.
FCFS leads to the convoy effect. It does not lead to the convoy effect.
FCFS algorithm is the easiest to implement in any system. The real difficulty with SJF is knowing the length of the next CPU request or burst.
A process may have to wait for quite long to get executed depending on the burst time of the processes that have arrived first. A long process may never get executed and the system may keep executing the short processes.
FCFS lead to lower device and CPU utilization thereby decreasing the efficiency of the system. SJF leads to higher effectiveness of the system due to lower average waiting time.
FCFS results in minimal overhead. In case of SJF, elapsed time should be recorded, results in more overhead on the processor.