-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSJF
57 lines (49 loc) · 1.42 KB
/
SJF
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
#include <stdio.h>
int main()
{
int n;
printf("Enter the no. of process");
scanf("%d",&n);
int arr[n][2],burst[n];
for(int i=0;i<n;i++)
{
printf("\n enter the arrival, burst time and priority number for the %dth process\t",i+1);
scanf("%d %d", &arr[i][0], &arr[i][1]);
burst[i] = arr[i][1];
}
int wait[n], tat[n], prev[n];
int t = 0, averageTAT = 0, averageWait = 0;
while(1)
{
int ind = 0, mini = 100000;
//Finding minimum priority
for(int i = 0; i < n; i++) // t is completion time of prev process
{
if(t >= arr[i][0] && arr[i][1] > 0 && mini > arr[i][1])
{
mini = arr[i][1];
ind = i;
}
}
if(mini == 100000)
break;
t+=arr[ind][1];
arr[ind][1] = 0;
tat[ind] = t;
}
for(int i=0;i<n;i++)
{
tat[i]=tat[i] -arr[i][0];
wait[i]=tat[i]-burst[i];
averageTAT+=tat[i];
averageWait+=wait[i];
}
double a=averageTAT/(1.0*n), b=averageWait/(1.0*n);
printf("Process no.\t Arrival time \t Burst Time \t Waiting Time \t Turnaround Time\n");
for(int i=0;i<n;i++)
{
printf("%d\t\t %d\t\t %d \t\t%d\t\t%d\n",i+1,arr[i][0],burst[i],wait[i],tat[i]);
}
printf("The average wait time is: %lf and the average turn around time is: %lf",b,a);
return 0;
}