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

Business Notes

bossiness notes

Uploaded by

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

Business Notes

bossiness notes

Uploaded by

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

Pid,bt,wt,&tat

Step 9: End

PROGRAM: SJF CPU SCHEDULING ALGORITHM

#include<stdi
o.h> int main()
{
int i,j,k,n,temp;

int p[10],bt[10],wt[10],tat[10];
float avgtat,avgwt;
printf("enter no of processes: \t");
scanf("%d",&n);
for(i=0;i<n;i++)
{

printf("enter process
name:\t"); scanf("%d",&p[i]);
printf("enter burst time \t");
scanf("%d",&bt[i]);
}

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

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

if(bt[i]<bt[j])

temp=
bt[i];
bt[i]=bt
[j];
bt[j]=te
mp;
k=p[i];
p[i]=p[j];
p[j]=k;
}

avgwt=wt[0]=0;
avgtat=tat[0]=bt
[0];
for(i=1;i<n;i++)
{

wt[i]=wt[i-1]+bt[i-1];

tat[i]=wt[i]+bt[i];
avgwt=avgwt+wt[i];
avgtat=avgtat+tat[i];
}
printf("p_name\t B_time\t w_time\t
turnaroundtime\n"); for(i=0;i<n;i++)
printf("%d\t%d\t%d\t%d\n",p[i],bt[i],wt[i],tat[i]);
printf("\navg waiting time=%f\n", avgwt/n);
printf("avg tat time=%f\n", avgtat/n);
}

OUTPUT:

student@NNRG310:~/oslab$ ccsjf.c

student@NNRG310:~/oslab$ ./a.out

enter no of processes: 4
enter process name: 1

enter burst time 6

enter process name: 2

enter burst time 8

enter process name: 3

enter burst time 7

enter process name: 4

enter burst time 3

p_name B_time w_time turnaroundtime

4 3 0 3

1 6 3 9

3 7 9 16

2 8 16 24

avg waiting

time=7.000000 avg tat

time=13.000000

student@NNRG310:~/osl

ab$

You might also like