Write a C program to implement the FCFS (FIRST COME FIRST SERVE) scheduling algorithm
Description:
First-come, first-serve
scheduling (FCFS):
In this, which process
enter the ready queue first is served first. The OS maintains DS that is ready
queue. It is the simplest CPU scheduling algorithm. If a process requests the
CPU then it is loaded into the ready queue, which process is the head of the
ready queue, connect the CPU to that process.
Algorithm for FCFS
scheduling:
Step 1: Start the
process
Step 2: Accept the
number of processes in the ready Queue
Step 3: For each
process in the ready Queue, assign the process id and accept the CPU burst time
Step 4: Set the waiting
of the first process as ‘0’ and its burst time as its turnaround time
Step 5: for each
process in the Ready Queue calculate
(a) Waiting time for process
(n)= waiting time of process (n-1) + Burst time of process(n-1)
(b)Turn around time for
Process (n)= waiting time of Process(n)+ Burst time for process(n)
Step 6: Calculate
(c) Average waiting
time = Total waiting Time / Number of process
(d)Average Turnaround
time = Total Turnaround Time / Number of process
Step 7: Stop the
process
int main()
{
int n,a[10],b[10],t[10],w[10],g[10],i,m;
float att=0,awt=0;
for(i=0;i<10;i++)
{
a[i]=0; b[i]=0; w[i]=0; g[i]=0;
}
printf("enter the number of process");
scanf("%d",&n);
printf("enter the burst times");
for(i=0;i<n;i++)
scanf("%d",&b[i]);
printf("\nenter the arrival times");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
g[0]=0;
for(i=0;i<10;i++)
g[i+1]=g[i]+b[i];
for(i=0;i<n;i++)
{
w[i]=g[i]-a[i];
t[i]=g[i+1]-a[i];
awt=awt+w[i];
att=att+t[i];
}
awt =awt/n;
att=att/n;
printf("\n\tprocess\twaiting time\tturn arround time\n");
for(i=0;i<n;i++)
{
printf("\tp%d\t\t%d\t\t%d\n",i,w[i],t[i]);
}
printf("the average waiting time is %f\n",awt);
printf("the average turn around time is %f\n",att);
return 0;
}
OUTPUT:
enter the number of process 4
enter the burst times
4 9 8 3
enter the arrival times
0 2 4 3
process waiting
time turn arround time
p0
0
4
p1
2
11
p2
9
17
p3
18
21
the average waiting time is
7.250000
the average turn around time is
13.250000
Comments
Post a Comment