-
Notifications
You must be signed in to change notification settings - Fork 3
/
FCFS OS.c
55 lines (43 loc) · 1.14 KB
/
FCFS OS.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
int main() {
int arrT[10], netBT[10], finT[10], turnAT[10], waitT[10];
int i = 0, n;
float avgWT = 0, avgTAT = 0;
printf("Enter the no. of Process\n");
scanf("%d", &n);
printf("Enter the Arrival Time for the processes\n");
for(i = 0; i < n; i++)
{
scanf("%d", &arrT[i]);
}
printf("Enter the Net Burst Time for the processes\n");
for(i = 0; i < n; i++)
{
scanf("%d", &netBT[i]);
}
finT[0] = netBT[0] - arrT[0];
turnAT[0] = finT[0] - arrT[0];
waitT[0] = turnAT[0] - netBT[0];
for(i = 1; i < n; i++)
{
finT[i] = finT[i-1] + netBT[i];
turnAT[i] = finT[i] - arrT[i];
waitT[i] = turnAT[i] - netBT[i];
avgWT += waitT[i];
avgTAT += turnAT[i];
}
avgTAT += turnAT[0];
avgTAT = avgTAT/n;
avgWT = avgWT/n;
printf("Pro \t Ar.Tm \t N.B.T \t F.T \t T.A.T \t Wait Tme \n");
for(i = 0; i < n; i++)
{
printf("P[%d] \t %d \t %d \t %d \t %d \t %d\n",i , arrT[i], netBT[i], finT[i], turnAT[i], waitT[i]);
}
printf("Avg. waiting Time = %.2f ms \n", avgWT);
printf("Avg. Turn Around Time = %.2f ms \n", avgTAT);
return 0;
}