C C++

How to create priority Scheduling Algorithm in C++ and C4 min read

Today in this article I am going to show you how to create priorities in c++ and even c because most of the readers are asking the difference between c and c++ code.

What is Priority Scheduling Algorithm?

In priority scheduling algorithm each process has a priority associated with it and as each process hits the queue, it is stored in based on its priority so that process with higher priority are dealt with first. It should be noted that equal priority processes are scheduled in FCFS order.

To prevent high priority processes from running indefinitely the scheduler may decrease the priority of the currently running process at each clock tick (i.e., at each clock interrupt). If this action causes its priority to drop below that of the next highest process, a process switch occurs. Alternatively, each process may be assigned a maximum time quantum that it is allowed to run. When this quantum is used up, the next highest priority process is given a chance to run.

Table of Contents


The problem occurs when the operating system gives a particular task a very low priority, so it sits in the queue for a larger amount of time, not being dealt with by the CPU. If this process is something the user needs, there could be a very long wait, this process is known as “Starvation” or “Infinite Blocking”.


Many operating systems use a technique called “aging”, in which a low priority process slowly gains priority over time as it sits in the queue. Even if, the priority of the process is low, there is a surety of its execution.

C Program

C++ Program

Take your time to comment on this aritcle.

Leave a Comment