DATE : 29/09/2020
To implement process scheduling using shortest job first scheduling algorithm
ta[c]=ct[c]-at[c]
wt[c]=ta[c]-bt[c]
#include<stdio.h>
int main() {
int pid[20] = {
0
}, at[10] = {
0
}, bt[10] = {
0
}, ct[10] = {
0
}, ta[10] = {
0
}, wt[10] = {
0
}, f[10] = {
0
};
int n, st = 0, tot = 0;
float avgwt = 0, avgta = 0;
printf("Enter total number of processes ");
scanf("%d", & n);
printf("Enter arrival time and burst time for each process\\n\\n");
for (int i = 0; i < n; i++) {
printf("Arrival time of process[%d] scanf(" % d ",&at[i]);
printf("Burst time of process[%d] ", i + 1); scanf("%d", & bt[i]); printf("\\n"); pid[i] = i + 1; f[i] = 0;
}
while (1) {
int c = n, min = 999;
if (tot == n) break;
",i+1);
for (int i = 0; i < n; i++) {
if ((at[i] <= st) && (f[i] == 0) && (bt[i] < min)) {
min = bt[i];
c = i;
}
}
if (c == n)
st++;
else {
ct[c] = st + bt[c];
st += bt[c];
ta[c] = ct[c] - at[c];
wt[c] = ta[c] - bt[c];
f[c] = 1;
tot++;
}
}
printf("\\npid arrival burst complete turn waiting\\n");
for (int i = 0; i < n; i++) {
avgwt += wt[i];
avgta += ta[i];
printf("P%d\\t %d\\t %d\\t %d\\t %d\\t %d\\n", i + 1, at[i], bt[i], ct[i], ta[i], wt[i]);
}
printf("\\naverage tat is %f", (float)(avgta / n));
printf("\\naverage wt is %f", (float)(avgwt / n));
}