UNIX C Program for Shortest Job First Scheduling Algorithm | CS1254-Operating Systems Lab


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

SOURCE CODE:
#include<stdio.h>
main()
{
int n,j,temp,temp1,temp2,pr[10],b[10],t[10],w[10],p[10],i;
float att=0;awt=0;
for(i=0;i<10;i++)
{
   b[i]=0;w[i]=0;
}
printf(“Enter the number of process:”);
scanf(“%d”,&n);
printf(“\n Enter the burst time”);
for(i=0;i<n;i++)
{
scanf(“%d”,&b[i]);
p[i]=i;
}
for(i=0;i<n;i++)
{
for(j=1;j<n;j++)
{
if(b[i]>b[j]
{
temp=b[i];
temp1=p[i];
b[i]=b[j];
p[i]=p[j];
b[j]=temp;
p[j]=temp1;
}
}
w[0]=0;
for(i=0;i<n;i++)
w[i+1]=w[i]+b[i];
for(i=0;i<n;i++)
{
t[i]=w[i]+b[i];
awt=aw+w[i]:
att=att+t[i];
}
awt=awt/n;
att=att/n;
printf(“\n\t Process \tWaitimgtime \t Turnaroundtime\n);
for(i=0;i<n;i++)
printf(“\t  p[%d] \t %d\t\t %d\n”,p[i].w[i],t[i]);
printf(“\n The average waiting time is %t \n”,awt);
printf(“The average turnaround time is %f\n”,att);
return 1;
}

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

Process        Waiting time         Turnaround time
 P[4]                   0                               1
 P[0]                   1                               6
 P[1]                   6                               10
 P[2]                   10                             13
 P[3]                   13                             15

The average waiting time is 6.000000
The average turnaround time is 9.000000
Previous
Next Post »

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