Professional Documents
Culture Documents
Theory and concept:- Shortest job first (SJF) scheduling is a policy, the
process with the shortest expected processing time is selected for the
execution. If two processes have same expected processing time, then at
FCFS scheduling is used to break tie.
Program :
# include <stdio.h>
# include <conio.h>
struct process
{
int pid ;
int burst ;
int wait ;
};
void main()
{
process p[5] , temp ;
int i,j,wait=0 ;
int twait=0.0 ;
for(i=0;i<5;i++)
{
p[i].pid = i+1 ;
printf("\nprocess p%d\n",i+1) ;
printf("\nenter burst time\n");
scanf("%d",&p[i].burst);
}
for(i=0;i<5;i++)
{ for(j=0;j<5;j++)
{
if(p[j].burst>p[i].burst)
{
temp=p[i];
p[i]=p[j] ;
p[j]=temp;
}
}
}
printf("\nprocess\t\tburst time\t\twaiting time\n");
for(i=0;i<5;i++)
{
p[i].wait=wait ;
twait = twait+wait ;
wait = wait + p[i].burst ;
printf("\np%d\t\t%d\t\t%d\n",p[i].pid,p[i].burst,p[i].wait);
}
printf("\n\n average waiting time %d",(twait/5));
getch();
}
Output:
Process p1
Process p2
Process p3
Process p5
Process p6
p2 1 0
p0 3 1
p1 4 4
p3 7 8
p4 8 15