C program for Priority Scheduling
#include<stdio.h> #include<conio.h> #include<iostream.h> void main() { clrscr(); 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(); }
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
June 1st, 2010 at 6:14 pm
//non -preemptive priority
#include
#include
main()
{
int p[10],wt[10],bt[10],tat[10],ttat=0,twt=0,i,j,temp,n,pri[10];
float awt,atat;
clrscr();
printf(“enter the no. of process=>\n”);
scanf(“%d”,&n);
printf(“enter process=>\n”);
for(i=0;i\n”);
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
printf("Enter the priority\n");
for(i=0;i<n;i++)
{
scanf("%d",&pri[i]);
}
for(i=0;i<n;i++)
{
for(j=0;jpri[j+1])
{
temp=p[j];
p[j]=p[j+1];
p[j+1]=temp;
temp=bt[j];
bt[j]=bt[j+1];
bt[j+1]=temp;
temp=pri[j];
pri[j]=pri[j+1];
pri[j+1]=temp;
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
twt=twt+wt[i];
}
for(i=0;i<n;i++)
{
tat[i]=wt[i]+bt[i];
ttat=ttat+tat[i];
}
awt=(float)twt/n;
atat=(float)ttat/n;
printf("p_no.\tP_bt\t p_wt\t p_tat\n");
for(i=0;i<n;i++)
printf("%d \t%d\t %d\t %d\n",p[i],bt[i],wt[i],tat[i]);
printf("total waiting time=%d\n avg waiting time=%f",twt,awt);
printf("\ntotal turnedaroundtime=%d\n avg turnedaround time=%f",ttat,atat);
getch();
}
June 1st, 2010 at 6:16 pm
#include
#include
void main()
{
int i,j,b[10],temp1,wt[10],tut[10],awt,atut,n,swt=0,stut=0,temp,pt[10];
clrscr();
printf(“Enter the no of jobs:”);
scanf(“%d”,&n);
printf(“Enter the burst time:”);
for(i=1;i<=n;i++)
scanf("%d",&b[i]);
printf("Enter the priorty of jobs:");
for(i=1;i<=n;i++)
scanf("%d",&pt[i]);
for(i=1;i<n;i++)
{
for(j=i;jpt[j])
{
temp=b[i];
b[i]=b[j];
b[j]=temp;
temp1=pt[i];
pt[i]=pt[j];
}
}
}
wt[1]=0;
for(i=2;i<=n;i++)
wt[i]=wt[i-1]+b[i-1];
for(i=1;i<=n;i++)
tut[i]=wt[i]+b[i];
for(i=1;i<=n;i++)
{
swt=swt+wt[i];
stut=stut+tut[i];
}
atut=stut/n;
awt=swt/n;
printf("Avg waiting time=%d\n",awt);
printf("Avg turn arround time=%d\n",atut);
getch();
}
August 2nd, 2010 at 11:31 am
sir i think ur source code is not purely correct
#include
#include
#include
void main()
{
clrscr();
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();
}
November 20th, 2010 at 11:46 pm
sir i want program of priority preemptive case…..
plz if u can help me as soon as possible…
January 26th, 2011 at 4:25 pm
We want sjf preemptive c program.
plz sir help us as soon as possible.
February 28th, 2011 at 1:58 pm
i want prirority shedulling which is compatible for linux operating system
please………………..as fast as u can sir
August 25th, 2011 at 1:31 pm
sir i want fcfs progam in c using arrival time,burst time
September 5th, 2011 at 10:09 pm
sir, actully this program are not so deficult but no body want to try…don’t post program…just post the idea of the program..like which logic will work..
September 5th, 2011 at 10:10 pm
//fcfs program
#include
#include
main()
{
float avgwt,avgtt;
char pname[10][10],c[10][10];
int wt[10],tt[10],bt[10],at[10],t,q,i,n,sum=0,sbt=0,ttime,j,ss=0;
printf(“\n\nEnter the number of processes:”);
scanf(“%d”,&n);
printf(“\n\n Enter the NAME, BURST TIME and ARRIVAL TIME of thr process”);
for(i=0;i<n;i++)
{
printf("\n\nNAME : ");
scanf("%s",&pname[i]);
printf("\n\nBURST TIME : ");
scanf("%d",&bt[i]);
printf("\n\n ARRIVAL TIME :");
scanf("%d",&at[i]);
}
for(i=0;i<n;i++)
for(j=i+1;jat[j])
{
t=at[i];
at[i]=at[j];
at[j]=t;
q=bt[i];
bt[i]=bt[j];
bt[j]=q;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}
}
wt[0]=0;
for(i=0;i<n;i++)
{
wt[i+1]=wt[i]+bt[i];
sum=sum+(wt[i+1]-at[i]);
tt[i]=wt[i]+bt[i];
ss=ss+bt[i];
}
avgwt=(float) sum/n;
avgtt=(float) sbt/n;
printf("\n\nAverage waiting time=%f",avgwt);
printf("\n\nAverage turn-around time=%f",avgtt);
printf("\n\n GANTT CHART\n");
for(i=0;i<n;i++)
{printf("|\t%s\t",pname[i]);
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%d\t\t",wt[i]);
}
printf("%d\n",ss);
printf("\n");
}
September 6th, 2011 at 3:18 pm
can any body give the source code of preemptive sjf (not non preemptive) as soon as possible….
September 20th, 2011 at 4:22 pm
#include
#include
void main()
{
int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,att,i,j;
clrscr();
printf(“Enter the number of process : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("\nProcess no %d : ",i+1);
scanf("%d" ,&pt[i]);
printf("\ntime priorities :");
scanf("%d",&pp[i]);
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(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];
att=t[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+pt[i];
att+=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;
att/=n;
printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",att);
getch();
}
September 20th, 2011 at 4:24 pm
hi thank u for giving me your code
i m from MIT college aurangabad
this is an re-designed code for the Priority job scheduling program using the C language
#include
#include
void main()
{
int x,n,p[10],pp[10],pt[10],w[10],t[10],awt,att,i,j;
clrscr();
printf(“Enter the number of process : “);
scanf(“%d”,&n);
for(i=0;i<n;i++)
{
printf("\nProcess no %d : ",i+1);
scanf("%d" ,&pt[i]);
printf("\ntime priorities :");
scanf("%d",&pp[i]);
p[i]=i+1;
}
for(i=0;i<n-1;i++)
{
for(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];
att=t[0];
for(i=1;i<n;i++)
{
w[i]=t[i-1];
awt+=w[i];
t[i]=w[i]+pt[i];
att+=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;
att/=n;
printf("\n Average Wait Time : %d \n",awt);
printf("\n Average Turn Around Time : %d \n",att);
getch();
}
September 26th, 2011 at 3:31 pm
we need fcfs sjf round robin n priority scheduling pgm tat should be v simple……make it as earlier as possible………………pls
October 22nd, 2011 at 6:16 pm
I need a easy implementation of LRU(least recently used) page replacement algorithm
November 24th, 2011 at 8:44 pm
/*The correct one is this for priority cpu sheduling
by :anaghvj*/
#include
#include
#include
void main()
{
int temp1,n,p[10],pp[10],pt[10],w[10],t[10],awt,atat,i,j;
clrscr();
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(j=i+1;jpp[j])
{
temp1=pp[i];
pp[i]=pp[j];
pp[j]=temp1;
temp1=pt[i];
pt[i]=pt[j];
pt[j]=temp1;
temp1=p[i];
p[i]=p[j];
p[j]=temp1;
}
}
}
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();
}
November 28th, 2011 at 5:37 pm
sir,
i want a program for priority scheduling by which we can solve response time also.
i want it asap…its really urgent.
if smebody knws please post it or send me a copy to my ,ail.
December 1st, 2011 at 12:25 am
#include
#include
void main()
{
int n,p[10],b[10],i,j,temp,temp1,pr[10],q[10];
float c,s=0.0;
clrscr();
printf(“Enter the no. of process\n”);
scanf(“%d”,&n);
printf(“Enter processes\n”);
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
printf("Enter brust time\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("Enter the priority\n");
for(i=0;i<n;i++)
{
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
{
for(j=1;j<n;j++)
{
temp=pr[i];
temp1=p[i];
pr[i]=pr[j];
p[i]=p[j];
pr[j]=temp;
p[j]=temp1;
}
}
for(i=0;i<n;i++)
{
printf("process is %d and it's Priority is %d\n",p[i],pr[i]);
}
p[0]=0;
for(i=0;i<n;i++)
{
p[i+1]=p[i]+b[i];
printf("Waiting time=%d\n",p[i]);
}
for(i=0;i<n;i++)
{
s=s+p[i];
}
c=s/n;
printf("Average waiting time=%f",c);
getch();
December 21st, 2011 at 10:56 pm
i want simple code for sjf preemptive
January 9th, 2012 at 3:39 pm
chaaaaaaaa
January 25th, 2012 at 2:54 pm
kal mera birthday hai……..
January 31st, 2012 at 3:16 pm
// non preemitive algorithm
#include
#include
void main()
{
int n,p[10],b[10],i,j,temp,temp1,pr[10],q[10];
float c,s=0.0;
clrscr();
printf(“Enter the no. of process\n”);
scanf(“%d”,&n);
printf(“Enter processes\n”);
for(i=0;i<n;i++)
{
scanf("%d",&p[i]);
}
printf("Enter brust time\n");
for(i=0;i<n;i++)
{
scanf("%d",&b[i]);
}
printf("Enter the priority\n");
for(i=0;i<n;i++)
{
scanf("%d",&pr[i]);
}
for(i=0;i<n;i++)
{
for(j=1;j<n;j++)
{
temp=pr[i];
temp1=p[i];
pr[i]=pr[j];
p[i]=p[j];
pr[j]=temp;
p[j]=temp1;
}
}
for(i=0;i<n;i++)
{
printf("process is %d and it's Priority is %d\n",p[i],pr[i]);
}
p[0]=0;
for(i=0;i<n;i++)
{
p[i+1]=p[i]+b[i];
printf("Waiting time=%d\n",p[i]);
}
for(i=0;i<n;i++)
{
s=s+p[i];
}
c=s/n;
printf("Average waiting time=%f",c);
getch();
}