in ,

Priority Scheduling Program In C

priority scheduling program in c.We know that different scheduling methods are employed to allocate resources to carry out various activities. Priority-based scheduling is one of these CPU methods.

Operating systems often use the C priority scheduling program to plan the execution of several processes as they enter the CPU.

Each process has a priority assigned to it, and the CPU is assigned to the process with the greatest priority.

Here, the term priority scheduling program in c comes in. so what is that? Let’s find out.

What is Priority Scheduling Algorithm?

Each process has a priority assigned to it in the priority scheduling method, and as each process enters the queue, it is stored according to its priority so that processes with higher priorities are handled first.

The scheduling of equal priority processes is done in FCFS order.

Every method is outlined as a Priority Number in an operating system’s priority-based scheduling algorithm. The processes are carried out based on this Priority Number.

In real-time systems, this scheduling approach is typically highly helpful. Priorities 1, 2, 3, and so forth are carried out in order starting with the process with the highest priority.

There are two types of schedules:

1.  Non-preemptive

According to this approach, the process that is now running is not interrupted if a new process with a higher priority than the one it is replacing arrives. The newly arrived process is instead elevated to the front of the ready queue.

2. Preemptive

It is a priority scheduling technique that preempts the CPU when a new process enters the system, meaning it will begin executing the new process if it has a higher priority than the one that is presently running.


  • According to the order of the processes, it schedules the procedure.
  • Lower number = higher priority
  • We schedule based on FCFS if two or more processes are equal in priority.
  • Starvation is a significant issue with priority scheduling.
  • Aging is a strategy for gradually raising the priority of the processes that have been waiting in the system for a long time. Aging is a solution to the problem of famine.

What criteria does the priority depend on?

Task priority can be decided either internally or externally.

Some of the internal variables include:

  • Time limits the process’s
  • memory needs
  • Time limits the process’s

While the external causes could include:

  • The task’s importance,
  • the amount allocated for computer use

The implementation

  • Enter the processes’ arrival time, burst time, and priority first.
  • The process with the lowest arrival time will be scheduled first; if there are two or more processes with the lowest arrival times, the process with the highest priority will be scheduled first.
  • Now, more procedures will be scheduled based on their arrival time and priority. Filter by process number if two processes have the priority equal.
  • We can schedule the processes based on their priority after they have all arrived.

Note: They will make it very obvious in the question which number has higher priority and which number has lesser priority.

Priority Scheduling Program In C Priority Scheduling Program In C :


The issue arises when the operating system assigns a task a very low priority, causing it to wait in the queue for a longer period without being completed by the CPU.

This technique also referred to as “Starvation” or “Infinite Blocking,” could result in a very long wait if the user needs it.


Numerous operating systems employ a process known as “aging,” in which a low-priority operation gradually gains priority while waiting in the queue.

The process will be carried out even if it is not given high priority.

Also, Read For Your Career: What companies are in the consumer services field?

Priority Scheduling Program In C :

void main()
   int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;

   printf("Enter the number of process : ");

   printf("\n Enter process : time priorities \n");

      printf("\nProcess no %d : ",i+1);
      scanf("%d  %d",&pt[i],&pp[i]);
      p[i]=i+1;  //this contains process numbers

//This section sorting burst time, priority and process number in ascending order using selection sort
     for(int j=i+1;j<n;j++)

w[0]=0; //waiting time for first process is zero

//calculate waiting time

printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time   Priority \n");


  printf("\n %d \t\t %d  \t\t %d \t\t %d \t\t %d \n",p[i],pt[i],w[i],t[i],pp[i]);

awt/=n; //calculte average waiting time
atat/=n; //calculte average turnaround time

printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",atat);

Priority Scheduling Program In C Output:

Enter the number of process : 4

 Enter process : time priorities

Process no 1 : 6


Process no 2 : 2

Process no 3 : 14

Process no 4 : 6

 Job  Burst Time      Wait Time    Turn Around Time   Priority

 3        14               0              6               14

 2         2               14             11              16

 1         6               16             15              22

 4         6               22             18              28

 Average Wait Time : 13

 Average Turn Around Time : 20

Written by webwoob

Leave a Reply

Your email address will not be published.


Bottled and jarred packaged goods


what will be the output of the following python code MCQ question