Open In App

Difference between Priority scheduling and Shortest Job First (SJF) CPU scheduling

1. Priority Scheduling Algorithm :
Priority scheduling algorithm executes the processes depending upon their priority. Each process is allocated a priority and the process with the highest priority is executed first. Priorities can be defined internally as well as externally. Internal priorities are decided by the system depending upon the number of resources required, time needed etc. whereas external priorities are based upon the time in which the work is needed or the amount being paid for the work done or the importance of process. Priority scheduling can be preemptive or non- preemptive.

Note –



Disadvantages:
The major problem is the starvation or indefinite blocking. It may so happen that in stream of processes, the system keeps executing the high priority processes and the low priority processes never get executed.

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.

Note –
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 Shortest job first (SJF) and Priority Scheduling algorithm are as follows:

Shortest job first (SJF) Priority scheduling
Shortest Job First (SJF) executes the processes based upon their burst time i.e. in ascending order of their burst times. Priority scheduling executes the processes based upon their priorities i.e. in descending order of their priorities. A process with higher priority is executed first.
SJF is also non-preemptive but its preemptive version is also there called Shortest Remaining Time First (SRTF) algorithm. Priority scheduling is both preemptive and non preemptive in nature.
The average waiting time for given set of processes is minimum. There is no idea of average waiting time and response time.
The real difficulty with SJF is knowing the length of the next CPU request or burst. It is quite easy to implement and best for real time operating systems.
A long process may never get executed and the system may keep executing the short processes. The problem of blocking of a process can be solved through aging which means to gradually increase the priority of a process after a fixed interval of time by a fixed number.

Article Tags :