First Come First Served (FCFS) is a non-preemptive scheduling algorithm in data structures also known as FIFO (First In, First Out) and FCFC (First Come, First Choice). This algorithm is the easiest to develop and utilize as it is based on the principle that processes/tasks are resolved in order of arrival.
How FCFS works
A process has three states: running, ready, and blocked. While the first process runs, the second is ready and the remainder of the processes are blocked. This is because the PCB is linked to the tail of the queue and only when the operating CPU is free can it be linked to the next task at the beginning of the line.
How it’s used
FCFS is used mostly in batch systems, where there is no need for communication between the user and the computer. Examples of FCFS usage are in payroll, generation of bills, and processing customer service requests. In deciding to use FCFS algorithms, the following calculations should be put into consideration:
- Wait times = start time – arrival time/number of tasks or processes.
- Turnaround time = completion time – arrival
Pros and cons
FCFS ensures that one process does not monopolize the processor. FCFS is non-preemptive allowing it to terminate use when a process is finished and can self-regulate between running and stalling stages, Due to the easy program, it is user-friendly and can be implemented almost anywhere. It is also fair.
However, due to the sequences’ integrity, FCFS programs often have high wait times. In addition, because it is non-preemptive, there is no sense of priority; smaller important tasks are often stalled behind larger negligible ones. This inefficiency is known as the Convoy Effect and can waste CPU resources.
A similar algorithm – Context Switching can be used in place of FCFS. Context Switching allows the CPU to tailor its queue in order of priority and wait time. However, this too can prove to be ineffective if there is a constant flow of tasks to align and adjust while the CPU is running.