What is shortest job first ( sjf ) Scheduling Algorithm?

The shortest job first scheduling algorithm work following  the process,  processor  selects the waiting process with the shortest or smallest execution time to execute next propcess.

Shortest job first in mining not first come and first serve. job first come and this program check and arrange  assenting reader fowling the  Burst time. shortest Burst time job first process

#include<stdio.h>
int main()
{

int n,j,diu,diu1,diu2,pr[10],burst[10],t[10],witing[10],p_index[10],i;
float avgtt=0,avgwt=0;
printf("Number of Process: ");
scanf("%d",&n);

for(i=0;i<n;i++){
     printf("Burst time for P[%d] : ",i);
            scanf("%d",&burst[i]);  /* taking Process Burst */
                    p_index[i]=i;  /*  indexing different array */
            }
for(i=0;i<n;i++){
   for(j=i;j<n;j++){
        if(burst[i]>burst[j])    /* value and array index arrange */  
                {
                diu=burst[i];
                diu1=p_index[i];
                burst[i]=burst[j];
                p_index[i]=p_index[j];
                burst[j]=diu;
                p_index[j]=diu1;
                }
            }
    }
witing[0]=0;
for(i=0;i<n;i++)
witing[i+1]=witing[i]+burst[i];   /*Calculating waiting time*/

for(i=0;i<n;i++)  /*Calculating turnaround time */
{t[i]=witing[i]+burst[i];
            avgwt=avgwt+witing[i];
            avgtt=avgtt+t[i];
        }
avgwt=avgwt/n;
avgtt=avgtt/n;
printf("\n\t p_indexe     start        End\n");
printf("\n\t --------     ------       ------\n");
for(i=0;i<n;i++)
printf("\t P[%d]=>\t\t %d \t   %d \n",p_index[i],witing[i],t[i]);
printf("\n\t --------     ------       ------\n");
    printf("\n\n Average Waiting Time:%f",avgwt);
    printf("\n Average Turnaround Time:%f \n\n\n\n",avgtt);

    return 0;
}

What is shortest job first ( sjf ) Scheduling Algorithm?

Leave a reply