Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
First-Come, First-Served (FCFS) Scheduling Algorithm
1. Introduction
The First-Come, First-Served (FCFS) scheduling algorithm is the most basic form of CPU scheduling. It
operates based on the simple principle that the process which requests the CPU first is allocated the CPU
first. This scheduling method is analogous to a First-In-First-Out (FIFO) queue system, where processes
are lined up in the order of their arrival.
The FCFS algorithm is non-preemptive, meaning that once the CPU has been allocated to a process, it
cannot be taken away until the process completes or voluntarily releases it (for example, by making an
I/O request).
2. Algorithmic Steps
1. All incoming processes are added to the ready queue upon arrival.
2. The ready queue is maintained in the order of arrival time.
3. The CPU is allocated to the process at the head of the queue.
4. After the currently executing process finishes its CPU burst, it is removed from the queue.
5. The next process in the queue is then scheduled for execution.
6. The above steps repeat until all processes have been executed.
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
3. Flowchart
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
3. Pseudocode
function FCFS_Scheduling(processes):
Sort processes by arrival_time
current_time = 0
for each process in processes:
if current_time < process.arrival_time:
current_time = process.arrival_time
process.start_time = current_time
process.completion_time = current_time + process.burst_time
process.turnaround_time = process.completion_time -
process.arrival_time
process.waiting_time = process.turnaround_time -
process.burst_time
current_time = process.completion_time
Display all process data and compute average waiting and
turnaround times
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
4. Illustrative Example
Given Process Table:
Process Arrival Time Burst Time
P1 0 24
P2 0 3
P3 0 3
Assuming all processes arrive at time 0 and are served in the order P1 → P2 → P3, the Gantt chart is as
follows:
Gantt Chart:
Calculation of Waiting Times:
● P1: Waiting Time = 0
● P2: Waiting Time = 24
● P3: Waiting Time = 27
Average Waiting Time = (0 + 24 + 27) / 3 = 17 units
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
5. Convoy Effect and Performance Consideration
In dynamic environments, especially where both CPU-bound and I/O-bound processes coexist, FCFS can
result in a convoy effect. Consider a scenario with one CPU-bound process and several I/O-bound
processes:
● The CPU-bound process is scheduled first and occupies the CPU for a long duration.
● During this period, I/O-bound processes complete their I/O operations and enter the ready
queue.
● These I/O-bound processes, which require very short CPU bursts, must wait until the CPU-bound
process finishes.
● Once the CPU-bound process moves to I/O, the I/O-bound processes execute quickly, and the
CPU may then remain idle.
● The CPU-bound process then returns, and the cycle repeats.
This behavior causes:
● Reduced CPU and I/O device utilization.
● Longer response times for short jobs.
● Inefficiency in real-time or interactive systems.
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
6. Characteristics of FCFS
Advantages:
● Simple and easy to implement.
● Fair in the order of arrival.
Disadvantages:
● Long average waiting times, especially for short jobs arriving after long jobs.
● Not suitable for time-sharing or interactive systems.
● Prone to convoy effects.
● Non-preemptive, limiting responsiveness in real-time environments.
7. Suitability in RTOS Context
In embedded and real-time operating systems, the FCFS algorithm is generally not suitable where
deterministic response time and task preemption are required. Its non-preemptive nature can cause
critical real-time tasks to be blocked by long, lower-priority tasks, making it unreliable for time-sensitive
applications.
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
8. Implementation of FCFS algorithm in C
#include <stdio.h>
struct Process {
int pid;
int arrival_time;
int burst_time;
int completion_time;
int turnaround_time;
int waiting_time;
};
int main() {
int n, i;
float total_turnaround = 0, total_waiting = 0;
printf("Enter number of processes: ");
scanf("%d", &n);
struct Process p[n];
// Input
for (i = 0; i < n; i++) {
p[i].pid = i + 1;
printf("Enter Arrival Time and Burst Time for Process %d: ", i + 1);
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
scanf("%d %d", &p[i].arrival_time, &p[i].burst_time);
// Sort processes by arrival time (FCFS behavior)
for (i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (p[i].arrival_time > p[j].arrival_time) {
struct Process temp = p[i];
p[i] = p[j];
p[j] = temp;
int current_time = 0;
// Calculate times
for (i = 0; i < n; i++) {
if (current_time < p[i].arrival_time)
current_time = p[i].arrival_time;
p[i].completion_time = current_time + p[i].burst_time;
p[i].turnaround_time = p[i].completion_time - p[i].arrival_time;
p[i].waiting_time = p[i].turnaround_time - p[i].burst_time;
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
total_turnaround += p[i].turnaround_time;
total_waiting += p[i].waiting_time;
current_time = p[i].completion_time;
// Output
printf("\n%-5s %-13s %-11s %-17s %-17s %-13s\n",
"PID", "Arrival Time", "Burst Time", "Completion Time",
"Turnaround Time", "Waiting Time");
for (i = 0; i < n; i++) {
printf("P%-4d %-13d %-11d %-17d %-17d %-13d\n",
p[i].pid, p[i].arrival_time, p[i].burst_time,
p[i].completion_time, p[i].turnaround_time, p[i].waiting_time);
printf("\nAverage Turnaround Time: %.2f\n", total_turnaround / n);
printf("Average Waiting Time : %.2f\n", total_waiting / n);
return 0;
}
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
Test Case 1:
Process Arrival Time Process Time
1 0 5
2 0 10
Output:
Test Case 2:
Process Arrival Time Process Time
1 0 24
2 0 3
3 0 3
Output:
Marwadi University
Faculty of Technology
Department of Information and Communication Technology
Subject: RTOS Aim: Perform FCFS algorithm with flowchart and steps.
(01CT0819)
Task 1 Date: 11-04-2025 Enrollment No: 92100133081
9. References
1. Silberschatz, A., Galvin, P. B., & Gagne, G. (2018). Operating System Concepts (10th ed.). Wiley.
2. Tanenbaum, A. S., & Bos, H. (2014). Modern Operating Systems (4th ed.). Pearson.
3. Krishna, C. M., & Shin, K. G. (1997). Real-Time Systems. McGraw-Hill.
4. FreeRTOS.org. FreeRTOS Real-Time Operating System Documentation. Retrieved from:
https://www.freertos.org/