FCFS Scheduling Program in C (With Arrival Time and Output)

Overview
The FCFS scheduling program in C is one of the first programs a computer science student writes when learning operating system concepts. FCFS (First Come First Serve) is the simplest CPU scheduling algorithm: processes are executed in the order they arrive, with no preemption. This article delivers exactly what you need: a complete, compilable C program that handles arrival times and produces accurate waiting and turnaround times; its exact terminal output matching hand-computed values; a worked example with non-zero arrivals showing every calculation step; and an honest analysis of the convoy effect the failure mode that explains why no production OS uses pure FCFS.
Terms In First Come First Serve Scheduling
To learn First Come First Serve Scheduling in C language, we need to understand some basic terminologies related to this algorithm. Some of them are as follows:
Completion Time
Completion Time is defined as the time required by a process to get executed.
- Completion Time= (Turn Around Time - Waiting Time)
Build an AI-First Career, Master the Complete Skillset
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
AI Forward Deployed Engineer Program
Full-stack engineering, production AI and client-facing consulting
+1000 moreTurn Around Time
The Turn around time is defined as the time taken by a process to complete after the arrival time. Or simply we can say that turnaround time is the difference between the arrival and completion time of a process.
Waiting Time
The waiting time is defined as the difference between the turnaround time and burst time of a process.
What is FCFS Scheduling?
Disk Scheduling Algorithms in an operating system can be referred to as a manager of a grocery store that manages all the incoming and outgoing requests for goods of that store. He keeps a record of what is available in-store, what we need further, and manages the timetable of transaction of goods. Just like that, a 'Disk Scheduling Algorithm' is an algorithm that keeps and manages incoming and outgoing requests from a disk in a system.

And the FCFS ( First Come First Serve) algorithm is one of the simple and easy types of disk scheduling algorithms for an operating system. Suppose there is an n number of processes named P1, P2, P3, P4..., Pn. Then all these processes will be processed at the CPU in a sequential manner first the process P1 will be scheduled by the algorithm and this will get executed and then process P2. and so on. Sometimes, Starvation can be seen in this algorithm if the burst time of a particular job is the longest among all the given jobs.
Characteristics of FCFS:
| Attribute | Value |
|---|---|
| Type | Non-preemptive |
| Queue discipline | FIFO (First In, First Out) |
| Selection criterion | Earliest arrival time |
| Starvation | No starvation but long processes cause severe waiting times via the convoy effect |
| Complexity | O(n log n) for sorting; O(n) for execution |
FCFS is the baseline against which all other scheduling algorithms are measured. [Learn more about first come first serve scheduling in OS]
Terms Used in FCFS Scheduling
Before writing the program, establish these four terms precisely they are where most calculation errors originate.
Completion Time (CT)
The time at which a process finishes execution.
Formula: CT = Start Time + Burst Time
Turn Around Time (TAT)
The total time a process spends in the system from arrival to completion.
Formula: TAT = CT − AT
Waiting Time (WT)
The time a process spends waiting in the ready queue before it first gets the CPU and any time it is preempted or waiting for I/O. In non-preemptive FCFS, WT = TAT − BT because a process runs continuously once started.
Formula: WT = TAT − BT = CT − AT − BT
Response Time (RT)
The time from arrival until the process first gets the CPU. In non-preemptive FCFS, response time equals waiting time because a process starts the instant it's first scheduled and is never interrupted.
Formula: RT = Start Time − AT
Algorithm
The algorithm for the FCFS Scheduling program in C is as follows:
- At first, the process of execution algorithm starts
- Then, we declare the size of an array
- Then we get the number of processes that need to insert into the program
- Getting the value
- Then the first process starts with its initial position and the other processes are in a waiting queue.
- The total number of burst times is calculated.
- The value is displayed
- At last, the process stops.
How Scaler Transformed Careers in Different Fields
Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.
Example
Let us see an example of some processes that are arriving in a sequence. Let's say there are four processes named P2, P3, and P1. Each of these tasks is arriving in accordance with their execution time. Given below is a table showing the jobs, execution time, and order of arrival.
| Process | Order of Arrival | Execution Time (in sec) |
|---|---|---|
| P1 | 3 | 15 |
| P2 | 1 | 3 |
| P3 | 2 | 3 |
According to the above table, the waiting time of process P2 is 0, the waiting time of process P3 is 3 and the waiting time of process P1 is 6. So we will calculate the average time as: Average time = (0 + 3 + 6)/3 = 3m sec Here the arrival time is taken as 0 so the turnaround time and the completion time are the same.
Code Implementation
Now, let us see how the concept of the algorithm of the FCFS Scheduling program in C can be implemented in the c language.
Output:
Explanation
In the above example, we saw how the FCFS scheduling algorithm can be implemented using the C language. At first, the total number of processes is taken as input by the user. After entering the number of processes, we need to provide the burst time for every number of processes that we entered first. And the waiting time is calculated according to the given inputs. The waiting time is calculated with the help of the burst time provided.
Then the turnaround time is calculated. For each of the given burst times and waiting times, the turnaround time is calculated by adding them. Then the average turnaround time andwaiting time is calculated in this part:
This calculation gives us the total number of processes present there. For getting the average time, the sum of waiting times and turnaround times are divided. This is the working of the algorithm of the FCFS Scheduling program in C.
Advantages of FCFS Scheduling
- Implementation is easy the concept of FCFS is that the job that comes first will be served first.
- In FCFS Scheduling program in C, there is no chance of starvation.
- FCFS Scheduling program in C is the simplest form of scheduling algorithm in an operating system.
Disadvantages of FCFS Scheduling
- In the algorithm of the FCFS Scheduling program in C, the 'Seek time' increases.
- This algorithm is not so efficient because of its simplicity.
Frequently Asked Questions
Turn Learning into Career Growth
How do I handle arrival times in an FCFS program in C?
Sort the processes by arrival time before scheduling, then set each process's start time to max(time the CPU became free, its arrival time). If the CPU frees up before the next process arrives, it idles. Waiting time is then Completion − Arrival − Burst. The main program above demonstrates this with a stable insertion sort.
Why does my average waiting time differ from the textbook answer?
Almost always the arrival times. WT = CT − AT − BT, not CT − BT. With arrivals 0, 1, 2, 3 the average waiting time is 5.75; with the same bursts all arriving at 0 it is 7.25 identical Gantt chart, different answer. If your output shows 7.25 when you expected 5.75, check whether you accidentally set all arrival times to 0.
How do I add a Gantt chart to my FCFS program?
Print one segment per process in execution order, each showing the process ID with its start and completion time, and insert an IDLE block wherever the next arrival is later than the previous completion. The main program above does this in a single loop: it checks whether start[i] > ct[i-1] and prints an IDLE segment if so.
Is FCFS preemptive or non-preemptive?
Non-preemptive. Once a process gets the CPU it runs to completion; a shorter process arriving later cannot interrupt it. That is exactly what produces the convoy effect—long processes block short ones with no mechanism to overtake.
What is the convoy effect in FCFS scheduling?
When one long process holds the CPU while short processes queue behind it. With bursts 20, 2, 2, 2 the average waiting time is 16.5 if the long process runs first and 3.0 if it runs last 5.5× worse, with no change in total completion time. Both orders finish at the same time (t = 26); only the distribution of waiting changes.
Can I write the same FCFS program in C++ or Java?
Yes. The logic is identical: sort by arrival time, compute completion, turnaround and waiting time. Only the I/O changes cin/cout in C++, Scanner and System.out.printf in Java. The arrays and the two formulas (TAT = CT − AT, WT = TAT − BT) stay the same.
What is the full form of FCFS?
FCFS stands for First Come First Served (also written First Come First Serve), a non-preemptive CPU scheduling algorithm that runs processes in order of arrival.
Summary
FCFS (First Come First Serve) is the simplest scheduling algorithm processes run in arrival order, non-preemptively and the baseline for all others. The two formulas to remember are TAT = Completion − Arrival and WT = TAT − Burst. The critical insight is that waiting time subtracts arrival time: processes that haven't arrived yet aren't waiting, which is why staggered arrivals reduce average waiting time even with an identical Gantt chart.
The convoy effect demonstrates that FCFS is not slow it is unfair. Both execution orders finish at the same time; only the distribution of waiting changes. SJF is provably optimal for average waiting time precisely because it schedules the shortest job first, eliminating the convoy. Round Robin approximates SJF's fairness without requiring advance knowledge of burst times.
CPU scheduling is one of the OS fundamentals that placement and GATE interviews return to repeatedly. Scaler Academy covers OS, DSA, DBMS and system design as a structured, mentor-led sequence. Explore Scaler Academy →