UNIX C Program for Priority Scheduling Algorithm | CS1254-Operating Systems Lab


AIM:
To write a LINUX/UNIX C Program for the Implementation of Priority Scheduling Algorithm in CS1254 - Operating Systems Laboratory.

SOURCE CODE:
#include<stdio.h>
#include>math.h>
#define MAX20
main()
{
int arrival[MAX];
int burst[MAX];
int prior[MAX];
int n,i,t1=0,t2=0,j,temp,temp1,temp2,tot=0;
float avg=0.0,wait=0.0;
printf(“Enter the number of jobs: ”);
scanf(“%d”,&n);
for(i=0;i<=n;i++)
{
printf(“Enter the arrival time: ”,i+1);
scanf(“%d”,&arrival[i]);
printf(“Enter the burst time: ”,i+1);
scanf(“%d”,&arrival[i]);
printf(“Enter the priority time: ”,i+1);
scanf(“%d”,&prior[i]);
}
printf(“Priority \t Arrival \t Burst time \t Turnaround time”);
for(i=1;i<n;i++)
{
for(j=1;j<=n;j++)
{
if(prior[i]>prior[j])
{
temp2=prior[i];
prior[i]=prior[j];
prior[j]=temp2;
temp=arrival[j];
arrival[i]=arrival[j];
arrival[j]=temp;
temp1=burst[i];
burst[i]=burst[j];
burst[j]=temp1;
}
}
tot=burst[i]+tot;
printf(“\n %d \t %d \t %d \t %d”,arrival[i],prior[i],burst[i],tot);
}
for(i=1;i<=n;i++)
{
t1=t2;
t2=t1+burst[i];
printf(“\n Process %d \t Waitingtime is: %d \n”,i,t1);
wait=wait+t1;
}
avg=wait/n;
printf(“The average waiting time is %f \n”,avg);
}


OUTPUT:
[examuser35@localhost Jebastin]$ cc priority.c
[examuser35@localhost Jebastin]$ ./a.out
Enter the number of jobs: 3
Enter the arrival time: 1
Enter the burst time: 3
Enter the priority time: 2
Enter the arrival time: 3
Enter the burst time: 1
Enter the priority time: 2
Enter the arrival time: 5
Enter the burst time: 3
Enter the priority time: 1

Priority    Arrival    Burst time    Turnaroundtime
5               1               3                           3
5               1               3                           6
5               1               3                           9

 process 1       waiting time is:0

 process 2       waiting time is:0

 process 3       waiting time is:1

The average waiting time is 0.333333
Previous
Next Post »

Still not found what you are looking for? Try again here.