Priority Scheduling Algorithm C Program

Let us learn how to implement priority scheduling algorithm in C programming with its explanation, output, advantages, disadvantages and much more.

What is Non-Preemptive Priority Scheduling Algorithm?

The priority scheduling algorithm is one of the most common algorithms for scheduling jobs in batch systems.

Every process is assigned a number which denotes the priority, and based on this priority the processes are executed. Therefore, the process having the highest priority (1) is executed first and then the priority 2, 3 and so on.

There can be some scenarios where more two or more processes may have the same priority. In this case, the processes are executed based on First In First Out order or in other words, First Come First Serve.

We do not consider the arrival time of the jobs in this non-preemptive priority scheduling algorithm. This means that unless a job gets completely executed, the CPU won’t leave the current job before it completes its execution.

Only once the process gets out of the job queue after successful execution, the CPU is allowed to process another job from the queue.

Advantages

This algorithm is very simple to implement.

The aging technique is implemented to reduce the starvation of lower priority processes.

Disadvantages

Starvation or indefinite blockage of the lower priority processes.

Since this is a non-preemptive implementation, the waiting time is comparatively higher.

The average turnaround time is higher as compared to the preemptive priority scheduling algorithm.

If a system failure occurs, all the unfinished lower priority jobs get vanished from the system.

Note: This implementation of non-preemptive priority scheduling program in C without arrival time is compiled with GNU GCC compiler using Linux terminal on Linux Ubuntu operating system.

The main issue with Priority Scheduling algorithm is Starvation, also called as Indefinite Blocking. It is overcome by Aging method where priorities are automatically decreased or increased based on the situation.