-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnon preemptive sjf arrival.txt
74 lines (62 loc) · 1.41 KB
/
non preemptive sjf arrival.txt
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
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,n,j,min,line[10],p[10];
int B_T[1000],A_V_T[1000],W_T[1000],temp;
int bt=0,ta=0,sum=0,k=1;
float avwt=0,wtsum=0;
cout<<"Enter the Number of processes :";
cin>>n;
cout<<"\npro AT BT\n";
for(i=0; i<n; i++)
{
cout<<"p"<<i+1<<" :";
cin>>A_V_T[i]>>B_T[i];
p[i]=i+1; //contains process number
}
for(i=0; i<n; i++)
{
for(j=0; j<n; j++)
{
if(A_V_T[i]<A_V_T[j])
{
swap(p[j],p[i]);
swap(A_V_T[j],A_V_T[i]);
swap(B_T[j],B_T[i]);
}
}
}
for(j=0; j<n; j++)
{
bt=bt+B_T[j];
min=B_T[k];
for(i=k; i<n; i++)
{
if (bt>=A_V_T[i] && B_T[i]<min)
{
swap(p[k],p[i]);
swap(A_V_T[k],A_V_T[i]);
swap(B_T[k],B_T[i]);
}
}
k++;
}
W_T[0]=0;
for(i=1; i<n; i++)
{
sum=sum+B_T[i-1];
W_T[i]=sum-A_V_T[i];
line[i]=W_T[i];
wtsum=wtsum+W_T[i];
}
avwt=(wtsum/n);
printf("\nProcess Name\tBurst Time\t Arrival Time\t Waiting Time" );
for(i=0; i<n; i++)
{
printf("\np%d\t\t%d\t\t %d\t\t %d",p[i],B_T[i],A_V_T[i],W_T[i]);
}
printf("\n\nAVERAGE WAITING TIME : %.2f",avwt);
printf("\n");
return 0;
}