-
Notifications
You must be signed in to change notification settings - Fork 0
/
fcfs.c
113 lines (105 loc) · 1.87 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include<stdio.h>
int main()
{
char pn[10];
int
arr[10],bur[10],star[10],finish[10],tat[1
0],wt[10],i,n;
int totwt=0,tottat=0;
printf("Enter the number of
processes:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter the Process Name, Arrival
Time & Burst Time:");
scanf("%s%d%d",&pn[i],&arr[i],&bur[i])
;
}
for(i=0;i<n;i++)
{
if(i==0)
{
star[i]=arr[i];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
else
{
star[i]=finish[i-1];
wt[i]=star[i]-arr[i];
finish[i]=star[i]+bur[i];
tat[i]=finish[i]-arr[i];
}
}
printf("\nPName Arrtime Burtime Start
TAT Finish");
for(i=0;i<n;i++)
{
printf("\n%s\t%6d\t\t%6d\t%6d\t%6d\
t%6d",pn[i],arr[i],bur[i],star[i],tat[i],fini
sh[i]);
totwt+=wt[i];
tottat+=tat[i];
}
printf("\nAverage Waiting time:%f",
(float)totwt/n);
printf("\nAverage Turn Around
Time:%f", (float)tottat/n);
}
SOURCE CODE:
/* A program to simulate the SJF CPU
scheduling algorithm */
#include<stdio.h>
#include<string.h>
main()
{
Int
i=0,pno[10],bt[10],n,wt[10],temp=0,j,tt
[10];
float sum,at;
printf("\n Enter the no of process ");
scanf(" %d",&n);
printf("\n Enter the burst time of each
process");
for(i=0;i<n;i++)
{
printf("\n p%d",i);
scanf("%d",&bt[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(bt[i]>bt[j])
{
temp=bt[i];
bt[i]=bt[j];
bt[j]=temp;
temp=pno[i];
pno[i]=pno[j];
pno[j]=temp;
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
wt[i]=bt[i-1]+wt[i-1];
sum=sum+wt[i];
}
printf("\n process no \t burst time\t
waiting time \t turn around time\n");
for(i=0;i<n;i++)
{
tt[i]=bt[i]+wt[i];
at+=tt[i];
printf("\n
p%d\t\t%d\t\t%d\t\t%d",i,bt[i],wt[i],tt[
i]);
}
printf("\n\n\t Average waiting
time%f\n\t Average turn around
time%f", sum/n,at/n);
}