0% found this document useful (0 votes)
8 views

SJF Without Arrival

operating system practical file
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

SJF Without Arrival

operating system practical file
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Experiment No.

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.

Goal: Minimize the average waiting time for processes.

Process Selection: The process with the shortest burst time is chosen to run next.

Program :
#include<stdio.h>

int main(){

int n, waiting_time = 0, turnaround_time = 0;;

printf("Enter the number of processes: ");

scanf("%d",&n);

int bt[n],wt[n],tt[n],pid[n],i,j;

for( i=0;i<n;i++)

printf("Enter process id : ");

scanf("%d",&pid[i]);

printf("Enter the burst time : ",i+1);

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("Process Id\tBurst time\tWaiting time\tTurnaround time\n");


for(i=0;i<n;i++){

printf("%d\t\t%d\t\t%d\t\t%d\n",pid[i],bt[i],wt[i],tt[i]);

printf("\nAverage Waiting Time: %.2f\n", (float)waiting_time / n);

printf("Average Turnaround Time: %.2f\n", (float)turnaround_time / n);

return 0;

Output :

You might also like