1.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.
2.Round-Robin (RR) :
Round-Robin (RR) Scheduling Algorithm is particularly designed for time sharing systems. The processes are put into the ready queue which is a circular queue in this case. In this case a small unit of time known as time quantum is defined. The algorithm selects the first process from the queue and executes it for the time defined by the time quantum. If the process has burst time less than the time quantum then the CPU executes the next process but if it has burst time higher than the time quantum then the process is interrupted and next process is executed for same time quantum. If a process is interrupted then a context switch happens and the process is put back at the tail of the queue. It is preemptive in nature.
This algorithm mainly depends on the time quantum. Very large time quantum makes RR same as the FCFS while a very small time quantum will lead to the overhead as context switch will happen again and again after very small intervals.
The major advantage of this algorithm is that all processes get executed one after the other which does not lead to starvation of processes or waiting by process for quite long time to get executed.
The difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithm are as follows:
|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.|
Attention reader! Don’t stop learning now. Learn all GATE CS concepts with Free Live Classes on our youtube channel.