-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathfcfs.c
86 lines (85 loc) · 1.86 KB
/
fcfs.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
79
80
81
82
83
84
85
86
#include<stdio.h>
int main()
{
int at[10],at2[10],bt[100],ex[100],seq[100],re[100],wt[100],tat[100];
int n,i,j,start,pos,max=0,min,idle=0,k=0;
float av1=0,av2=0;
printf("*****INPUT*****\n");
printf("Enter number of process\n");
scanf("%d",&n);
printf("Enter arrival time for processess\n");
for(i=0;i<n;i++)
{
scanf("%d",&at[i]);
at2[i]=at[i];
}
printf("Enter burst time for processess\n");
for(i=0;i<n;i++)
{
scanf("%d",&bt[i]);
}
start=at[0];
for(i=1;i<n;i++)
{
if(start>at[i])
{
start=at[i];
}
}
printf("*****OUTPUT*****\n");
printf("Sequence of execution is\n");
for(i=0;i<n;i++)
{
if(max<at[i])
{
max=at[i];
}
}
max=max+1;
for(i=0;i<n;i++,k++)
{ min=max;
for(j=0;j<n;j++){
if(at[j]!=-1)
{
if(at[j]<min)
{
min=at[j];
pos=j;
}
}
}
printf("[P%d] ",pos);
seq[k]=pos;
if(start<at[pos]){
re[pos]=start;
idle+=at[pos]-start;
start=at[pos];
start+=bt[pos];
at[pos]=-1;
ex[pos]=start;
}
else{
re[pos]=start;
start+=bt[pos];
at[pos]=-1;
ex[pos]=start;
}
}
printf("\n");
for(i=0;i<n;i++)
{
tat[i]=ex[i]-at2[i];
wt[i]=tat[i]-bt[i];
}
printf("Process Arrival-time(s) Burst-time(s) Waiting-time(s) Turnaround-time(s)\n");
for(i=0;i<n;i++)
{
printf("P%d %d %d %d %d\n",i,at2[i],bt[i],wt[i],tat[i]);
}
for(i=0;i<n;i++)
{
av1+=tat[i];
av2+=wt[i];
}
printf("Average waiting time(s) %f\nAverage turnaroundtime(s) %f\nCPU idle time(s)%d\n",av2/n,av1/n,idle);
}