As the name suggests, in the “First come first serve” scheduling algorithm, the process which arrives first, gets executed first, or we can say that the process which requests the CPU first, gets the CPU allocated first.
- First Come First Serve, is just like FIFO(First in First out) Queue data structure, where the data element which is added to the queue first, is the one who leaves the queue first.
- This is used in Batch Systems.
- It’s easy to understand and implement programmatically, using a Queue data structure, where a new process enters through the tail of the queue, and the scheduler selects process from the head of the queue.
- A perfect real life example of FCFS scheduling is buying tickets at ticket counter.
For Example : For every scheduling algorithm, Average waiting time is a crucial parameter to judge it’s performance.
Average waiting time is the average of the waiting times of the processes in the queue, waiting for the scheduler to pick them for execution.
Lower the Average Waiting Time, better the scheduling algorithm.
Consider the processes P1, P2, P3, P4 given in the below table, arrives for execution in the same order, with Arrival Time
0, and given Burst Time, let’s find the average waiting time using the FCFS scheduling algorithm.
The average waiting time will be
For the above given proccesses, first P1 will be provided with the CPU resources,
- Hence, waiting time for P1 will be
- P1 requires
15 msfor completion, hence waiting time for P2 will be
- Similarly, waiting time for process P3 will be execution time of P1 + execution time for P2, which will be
(15 + 4) ms=
- For process P4 it will be the sum of execution times of P1, P2 and P3 i.e. 24 ms.
Problems with FCFS Scheduling
Below we have a few shortcomings or problems with the FCFS scheduling algorithm:
- It is Non Pre-emptive algorithm, which means the process priority doesn’t matter.If a process with very least priority is being executed, more like daily routine backup process, which takes more time, and all of a sudden some other high priority process arrives, like interrupt to avoid system crash, the high priority process will have to wait, and hence in this case, the system will crash, just because of improper process scheduling.
- Not optimal Average Waiting Time.
- Resources utilization in parallel is not possible, which leads to Convoy Effect (Convoy Effect is a situation where many processes, who need to use a resource for short time are blocked by one process holding that resource for a long time.), and hence poor resource(CPU, I/O etc) utilization.