Write a C program to perform Priority Scheduling

By | 03.12.2016

C program to perform Priority Scheduling


Write a C program to perform Priority Scheduling.  Here’s a Simple program for priority scheduling algorithm in C Programming Language.

The Priority Scheduling Program in C Language is normally implemented in Operating Systems to schedule multiple process entering the CPU for execution. This code is for Priority Scheduling Non – Preemptive Algorithm in C Programming.


What is Priority Scheduling Algorithm?


In a Priority based Scheduling Algorithm in Operating Systems, every process is assigned a Priority Number. Based on this Priority Number, the processes are executed. This scheduling algorithm is normally very useful in real-time systems. The process having the highest priority (1) is executed first and then priority 2, 3 and so on.


Below is the source code for C Program to input values into an array and display them which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


#include<stdio.h>
#include<conio.h>
void main()
 {
   int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i;
   printf("Enter the number of process : ");
   scanf("%d",&n);
   printf("\n Enter process : time priorities \n");
   for(i=0;i<n;i++)
    {
      printf("\nProcess no %d : ",i+1);
      scanf("%d  %d",&pt[i],&pp[i]);
      p[i]=i+1;
    }
  for(i=0;i<n-1;i++)
   {
     for(int j=i+1;j<n;j++)
     {
       if(pp[i]<pp[j])
       {
         x=pp[i];
         pp[i]=pp[j];
         pp[j]=x;
         x=pt[i];
         pt[i]=pt[j];
         pt[j]=x;
         x=p[i];
         p[i]=p[j];
         p[j]=x;
      }
   }
}
w[0]=0;
awt=0;
t[0]=pt[0];
atat=t[0];
for(i=1;i<n;i++)
 {
   w[i]=t[i-1];
   awt+=w[i];
   t[i]=w[i]+pt[i];
   atat+=t[i];
 }
printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time   Priority \n");
for(i=0;i<n;i++)
  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;
atat/=n;
printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",atat);
getch();
}

OUTPUT : :


Enter the number of process : 4

 Enter process : time priorities

Process no 1 : 3
1

Process no 2 : 4
2

Process no 3 : 5
3

Process no 4 : 6
4


 Job     Burst Time      Wait Time       Turn Around Time   Priority

 4               6               0               6               4

 3               5               6               11              3

 2               4               11              15              2

 1               3               15              18              1

 Average Wait Time : 8

 Average Turn Around Time : 12

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach upto you in the short interval.


Thanks for reading the post.

3.3 21 votes
Article Rating
Subscribe
Notify of
guest

21 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Kurakula Venkateswaramma

Super explaination

Kurakula Venkateswaramma

Nice

ME MYSELF

NOT WORKING

sadhashivan

compile time I/O exception ninte appan nokkuo

Sathyamurthi

Ninte appan Manchatti Poori

sukumaran

EDA CWOMEDY!!
HAHAHA
LOL

Stephen nedumbally

ayin nee edha nayinte mone

Sugunan

Yema Pwoli Chekanmaar

sus-sheelan

nth chela aada nee??

rocky bhai

Aila Mathi Chura Kaari Kanava Kilimeen Køøri Karimeen
Vatta Vaala Braalu Chøraku Aikkøøra Nathøli
Aila Mathi Chura Kaari Kanava Kilimeen Køøri Karimeen
Vatta Vaala Braalu Chøraku Aikkøøra Nathøli

Su Su sundhareshan

ayinne,ni ethada myreee!!!

Stephen nedumbally

no bad word pls

xavierpundamon

vedi unda punda

swayyyy

umma on ur balls

zakaria pothen

balls venda nte butt edtho

pushpa raj

Oo Antava Mava
Oo Oo Antava Maava Hey
Oo Antava Mava
Oo Oo Antava Maava Hey

Su Su sundhareshan

Sudharan njanum,sundari niyum cherrnirunaale………….

Rocky Bhai

poo myre

Stephen nedumbally

suiiiiiiii
jaooooooo bomby valaaa
insta id tharuoooo setaaa….

Stephen nedumbally

njn vaishak , vjec student
___user_unknown___
follow me if u r single

text me if u wanna fall in lub

suiii

find hot single milfs in your area
meaasage instagram @deva_10