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.
- If two processes have the same priority then tie is broken using FCFS.
- The waiting time for the highest priority process is always zero in preemptive mode while it may not be zero in case of non preemptive mode.
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.
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.|
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Difference between Multi Level Queue Scheduling (MLQ) and Priority Scheduling
- Difference between Priority Scheduling and Round Robin (RR) CPU scheduling
- Difference between Priority Scheduling and Longest Job First (LJF)
- Difference between FCFS and Priority CPU scheduling
- Difference between Multi Level Queue Scheduling (MLQ) and Shortest Job First
- Difference between Shortest Job First (SJF) and Round-Robin (RR) scheduling algorithms
- Difference between Preemptive Priority based and Non-preemptive Priority based CPU scheduling algorithms
- Program for Priority CPU Scheduling | Set 1
- Priority CPU Scheduling with different arrival time - Set 2
- Program for Preemptive Priority CPU Scheduling
- Fixed-priority pre-emptive scheduling
- CPU Scheduling in Operating Systems using priority queue with gantt chart
- Program for Shortest Job First (or SJF) CPU Scheduling | Set 1 (Non- preemptive)
- Program for Shortest Job First (SJF) scheduling | Set 2 (Preemptive)
- Shortest Job First CPU Scheduling with predicted burst time
- Shortest Job First (or SJF) CPU Scheduling Non-preemptive algorithm using Segment Tree
- Multilevel Feedback Queue Scheduling (MLFQ) CPU Scheduling
- Difference between EDF and LST CPU scheduling algorithms
- Difference between SJF and LJF CPU scheduling algorithms
- Difference between LJF and LRJF CPU scheduling algorithms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.