FCFS - First Come First Serve
CPU Scheduling
First Come, First Serve (FCFS) is one of the simplest types of CPU scheduling
algorithms.
It is exactly what it sounds like: processes are attended to in the order in which
they arrive in the ready queue, much like customers lining up at a grocery store.
FCFS Scheduling is a non-preemptive algorithm, meaning once a process starts
running, it cannot be stopped until it voluntarily relinquishes the CPU, typically
when it terminates or performs I/O.
This method schedules processes in the order they arrive, without considering
priority or other factors.
How Does FCFS Work?
The mechanics of FCFS are straightforward:
Arrival: Processes enter the system and are placed in a queue in the
order they arrive.
Execution: The CPU takes the first process from the front of the
queue, executes it until it is complete, and then removes it from the
queue.
Repeat: The CPU takes the next process in the queue and repeats
the execution process.
Example of FCFS CPU Scheduling:
To understand the First Come, First Served (FCFS) scheduling
algorithm effectively, we'll use two examples -
one where all processes arrive at the same time,
another where processes arrive at different times.
Scenario 1: Processes with Same Arrival Time
Consider the following table of arrival time and burst time for three
processes P1, P2 and P3
Step-by-Step Execution:
P1 will start first and run for 5 units of time (from 0 to 5).
P2 will start next and run for 3 units of time (from 5 to 8).
P3 will run last, executing for 8 units (from 8 to 16).
AT : Arrival Time
BT : Burst Time or CPU Time
TAT : Turn Around Time
WT : Waiting Time
Scenario 2: Processes with Different Arrival Times
Consider the following table of arrival time and burst time for three
processes P1, P2 and P3.
Step-by-Step Execution:
P2 arrives at time 0 and runs for 3 units, so its completion time is:
Completion Time of P2=0+3=3
P1 arrives at time 2 but has to wait for P2 to finish. P1 starts at time
3 and runs for 5 units. Its completion time is:
Completion Time of P1=3+5=8
P3 arrives at time 4 but has to wait for P1 to finish. P3 starts at time
8 and runs for 4 units. Its completion time is:
Completion Time of P3=8+4=12
Advantages of FCFS
The simplest and basic form of CPU Scheduling algorithm
Every process gets a chance to execute in the order of its arrival. This
ensures that no process is arbitrarily prioritized over another.
Easy to implement, it doesn't require complex data structures.
Since processes are executed in the order they arrive, there’s no risk
of starvation
It is well suited for batch systems where the longer time periods for
each process are often acceptable.
Disadvantages of FCFS
As it is a Non-preemptive CPU Scheduling Algorithm, FCFS can result in
long waiting times, especially if a long process arrives before a shorter
one. This is known as the convoy effect, where shorter processes are
forced to wait behind longer processes, leading to inefficient execution.
The average waiting time in the FCFS is much higher than in the others
Since FCFS processes tasks in the order they arrive, short jobs may have
to wait a long time if they arrive after longer tasks, which leads to poor
performance in systems with a mix of long and short tasks.
Processes that are at the end of the queue, have to wait longer to finish.
It is not suitable for time-sharing operating systems where each process
should get the same amount of CPU time.