Search code examples
algorithmoperating-systemscheduling

How to schedule processes in FCFS algorithm using arrival time?


Here is my definition of FCFS (First Come First Serve - CPU Scheduling algorithm):

Process     CPU Burst        Arrival Time
p1          4                0
p2          5                1
p3          6                2
p4          5                1
p5          4                0

And the sequence of this example is as below enter image description here

So my question is that in second turn why it doesn't take p5 instead of p4 as its arrival time is also 0?


Solution

  • FCFS is implemented through Queue data structure. So it all depends on the position of processes in the FCFS queue, based on which short term scheduler will select process for execution.

    Since arrival time of p5 is less than p4, it will definitely be ahead of p4 in the queue and therefore, it must be executed first. The Gantt Chart you have drawn is wrong.

    One of the correct sequence could be:

    p1 , p5 , p2 , p4 , p3