Let us learn how to implement first come first serve algorithm in C programming with its explanation, output, advantages, disadvantages and much more.
What is First Come First Serve Disk Scheduling Algorithm?
The first come first serve algorithm is commonly abbreviated as FCFS algorithm. It primarily works on the First In First Out (FIFO) principle.
The incoming requests or jobs in the system queue are executed based on first come first served basis. This is a non-preemptive scheduling algorithm.
Therefore, once the CPU is allocated to a particular job, the job keeps on executing till it gets completed. The CPU cannot leave the current job before it gets completed. So, the CPU cannot move to another job in the queue.
The FCFS algorithm is usually represented using Gantt’s Chart on paper. However, the FCFS scheduling algorithm is not so efficient when it comes to performance optimization.
It is not optimized for time-sharing systems. The average waiting time for the first come first serve scheduling algorithm is highly dependent on the burst time of the jobs.
Advantages
- Simple and easy to implement
- Every process/job gets executed completely
- Lower possibilities of starvation
Disadvantages
- Poor performance due to high average waiting time
- There is no option for pre-emption of a job.
- Higher average turnaround time
- In-efficient for time-sharing systems
Note: This FCFS Algorithm C program is compiled with GNU GCC compiler using Linux terminal on Linux Ubuntu operating system.
First Come First Serve CPU Scheduling Algorithm C Program
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 | #include<stdio.h> int main() { float burst_time[30], waiting_time[30], turnaround_time[30]; float average_waiting_time = 0.0, average_turnaround_time = 0.0; int count, j, total_process; printf("Enter The Number of Processes To Execute:\t"); scanf("%d", &total_process); printf("\nEnter The Burst Time of Processes:\n\n"); for(count = 0; count < total_process; count++) { printf("Process [%d]:", count + 1); scanf("%f", &burst_time[count]); } waiting_time[0] = 0; for(count = 1; count < total_process; count++) { waiting_time[count] = 0; for(j = 0; j < count; j++) { waiting_time[count] = waiting_time[count] + burst_time[j]; } } printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time\n"); for(count = 0; count < total_process; count++) { turnaround_time[count] = burst_time[count] + waiting_time[count]; average_waiting_time = average_waiting_time + waiting_time[count]; average_turnaround_time = average_turnaround_time + turnaround_time[count]; printf("\nProcess [%d]\t\t%.2f\t\t%.2f\t\t%.2f", count + 1, burst_time[count], waiting_time[count], turnaround_time[count]); } printf("\n"); average_waiting_time = average_waiting_time / count; average_turnaround_time = average_turnaround_time / count; printf("\nAverage Waiting Time = %f", average_waiting_time); printf("\nAverage Turnaround Time = %f", average_turnaround_time); printf("\n"); return 0; } |
Output

If you have any doubts about the implementation of FCFS program in C language, let us know about it in the comment section. Find more about it here.
Sure. We are uploading other programs very soon.
I think SJF algorithm is more efficient than the FCFS algorithm due to its turnaround time.
FCFS algorithm does not seem to process efficiently. Its turnaround time is too much compared to other scheduling algorithms. Which is the best scheduling algorithm for CPU Scheduling in C Programming?
There is no such thing as which is the best. It all depends upon what work you intend the CPU to process. However, here are some of the most efficient CPU Scheduling Algorithms which you can implement in C Programming as well.
Great Program. Works perfectly fine. But it is quite difficult to grasp. However, it helped in my submissions! 🙂
Yes. It is a little difficult but not impossible. I would suggest you to solve few FCFS problems first. You will get the logic and converting it in a programming language would not be much harder then.
Can I implement a preemptive FCFS algorithm in C programming? Please help.
This is one of most basic disk schedulong algorithms and I do not recommend it to be used. They are way better cpu scheduling algorithms than this. See sjf, rr and many more.
The FCFS CPU Scheduling Algorithm is rarely used nowadays. However, it is used with some other algorithms as a part and combined to form a new algorithm. For example, a situation can be handled better by both SJF and FCFS algorithms when used together.
sir,
average_waiting_time=average_waiting_time/total_processes;
this is the correct one know sir??