SJF Without Arrival
SJF Without Arrival
5a
Objective :
Implement CPU Scheduling Policies of SJF algorithm without arrival time.
Theory :
Shortest Job First (SJF), also known as Shortest Job Next (SJN), is a CPU scheduling algorithm
that prioritizes processes with the shortest execution time.
Process Selection: The process with the shortest burst time is chosen to run next.
Program :
#include<stdio.h>
int main(){
scanf("%d",&n);
int bt[n],wt[n],tt[n],pid[n],i,j;
for( i=0;i<n;i++)
scanf("%d",&pid[i]);
scanf("%d",&bt[i]);
}
//Sort processes by burst time
for(i=0;i<n;i++){
for(j=0;j<n-i-1;j++){
if(bt[j]>bt[j+1]){
int temp=pid[j];
pid[j]=pid[j+1];
pid[j+1]=temp;
temp=bt[j];
bt[j]=bt[j+1];
bt[j+1]=temp;
wt[0]=0;
for(i=1;i<n;i++){
wt[i]=wt[i-1]+bt[i-1];
for(i=0;i<n;i++)
tt[i]=wt[i]+bt[i];
waiting_time+=wt[i];
turnaround_time+=tt[i];
printf("%d\t\t%d\t\t%d\t\t%d\n",pid[i],bt[i],wt[i],tt[i]);
return 0;
Output :