-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsjf-non-preemptive.c
78 lines (74 loc) · 1.75 KB
/
sjf-non-preemptive.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//shortest job first non preemptive
#include<stdio.h>
#include<string.h>
void main()
{
int i,j,n,Bt[10],wt[10],At[10],Tt=0;
char c[10][10],pn[10][10],s[10];
int z[50];
float Twt=0.0,Awt;
int w=0,temp,t;
printf("Enter no. of processes : ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Burst time for Process %d :",i+1);
scanf("%d",&Bt[i]);
printf("Enter the Arrival time for Process %d :",i+1);
scanf("%d",&At[i]);
s[i]='T';
Tt+=Bt[i];
}
for(i=0;i<n;i++)
{
for(j=2;j<n;j++)
{
if(Bt[j-1]>Bt[j])
{
temp=Bt[j];
Bt[j]=Bt[j-1];
Bt[j-1]=temp;
temp=At[j];
At[j]=At[j-1];
At[j-1]=temp;
strcpy(c[j-1],pn[j-1]);
strcpy(pn[j-1],pn[j]);
strcpy(pn[j],c[j-1]);
}
}
}
wt[0]=0;
z[0]=0;
w+=Bt[0];
t=w;
s[0]='F';
while(w<Tt)
{
i=1;
while(i<=n)
{
if(s[i]=='T' && At[i]<=t)
{
z[i]=w;
wt[i]=w-At[i];
s[i]='F';
w+=Bt[i];
t=w;
i=1;
}
else
i++;
}
}
printf("\nProcess \tBurst time\tArrival time \tWaiting time\n");
for(i=0;i<n;i++)
printf("\nProcess%d\t\t%d\t\t%d\t\t%d",i+1,Bt[i],At[i],wt[i]);
/* printf("\n\n Gannt Chart : \n");
for(i=0;i<n;i++)
printf("%4d",z[i]); */
for(i=0;i<n;i++)
Twt+=wt[i];
printf("\n\nTotal waiting Time : %f \t",Twt);
Awt=Twt/n;
printf("\nAverage waiting Time : %f\n\n",Awt);
}