Difference between FCFS and SJF CPU scheduling algorithms
1. First Come First Served (FCFS) :
First Come First Served (FCFS) is the simplest type of algorithm. It is a non-preemptive algorithm i.e. the process cannot be interrupted once it starts executing. The FCFS is implemented with the help of a FIFO queue. The processes are put into the ready queue in the order of their arrival time. The process that arrives first becomes the head of the queue while the others that arrive after are added to the rear of the queue. In First Come First Served (FCFS) algorithm, the process that arrives first, is sent first for execution by the CPU when CPU is free.
The main disadvantage of this algorithm is that the average waiting time is often quite long. It also leads to the convoy effect. This results in lower device or CPU utilization and lower efficiency.
2. Shortest Job First (SJF) :
Shortest Job First (SJF) Scheduling Algorithm is based upon the burst time of the process. The processes are put into the ready queue based on their burst times. In this algorithm, the process with the least burst time is processed first. The burst time of only those processes is compared that are present or have arrived until that time. It is also non-preemptive in nature. Its preemptive version is called Shortest Remaining Time First (SRTF) algorithm.
The major advantage of this algorithm is that it gives the minimum waiting time for a given set of processes and thus reduces the average waiting time. The disadvantage of this algorithm is that long processes may never be processed by the system and may remain in the queue for very long time leading to starvation of processes.
If two processes have same burst time then the tie is broken using FCFS, i.e., the process that arrived first is processed first.
The difference between First Come First Served (FCFS) and Shortest Job First (SJF) scheduling algorithm are as follows:
|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.|
Attention reader! Don’t stop learning now. Practice GATE exam well before the actual exam with the subject-wise and overall quizzes available in GATE Test Series Course.
Learn all GATE CS concepts with Free Live Classes on our youtube channel.