First Come First Serve Scheduling


This is the easiest scheduling technique to schedule processes in CPU but still many students fail to solve problems due to silly mistakes. I will give you detailed explanation of FCFS with its code so that you can implement it practically as well. So, let's start shall we?

As the name suggests "First Come First Serve" means the process which will come first will be executed first. It is just like queue data structure in which data is added and removed from the queue in FIFO order.
I will give you the code to implement FIFO where you will see that I have also used a queue data structure. In the implementation the process enters the queue from tail and it is removed from the queue from front
Let's understand FCFS with a real life example:
Let say you want to buy some items in a shop and a queue is formed outside the shop. So, the person who came first to the shop will buy items first and the person who came late will have to enter the queue through its tail.

Numerical:


First Come First Serve Scheduling

Draw Gantt chart for the above table of processes using FCFS and calculate waiting time and turn around time for each process.

-->
Since we know the process which will come first is executed first thus the first process is P1 which has a burst time of 4ms.
P1 will start execution in CPU. after 1ms of execution of P1 , P2 will come into ready queue but it would not interfere with P1 since FCFS is non-preemptive scheduling.
When P1 has executed for 2ms then another process P3 will be added to ready queue.
When P1 has executed for 3ms then another process P4 will be added to ready queue.
When P1 has executed for 4ms another process P5 will be added to ready queue.
Now P1 has completed its execution.
Now P2 will start its execution since it was the first to come into the ready queue.
P2 will execute for 3ms.
Then P3 will execute for 1ms.
Then P4 will execute for 2ms.
At last P5 will execute for 5ms.
The gantt chart is given below:

First Come First Serve Scheduling

The time indicate starting execution time and ending execution time for a process.
P1 started at 0ms and ended at 4ms.
            4ms - 0ms=4ms<-----burst time for P1
P2 started at 4ms and ended at 7ms.
            7ms - 4ms=3ms<----burst time for P2
P3 started at 7ms and ended at 8ms.
            8ms - 7ms=1ms<----burst time for P3
P4 started at 8ms and ended at 10ms.
            10ms - 8ms=2ms<----burst time for P4
P5 started at 10ms and ended at 15ms.
            15ms - 10ms=5ms<----burst time for P5

Waiting time for each process is given by starting execution time for a process - arrival time of that process.
process               starting execution time - arrival time                         Waiting time
P1                                                  0 - 0                                                             0ms
P2                                                  4 - 1                                                             3ms
P3                                                  7 - 2                                                             5ms
P4                                                  8 - 3                                                             5ms
P5                                                  10 - 4                                                           6ms

Turn around time for each process is given by ending execution time for a process - arrival time of that process.
process               ending execution time - arrival time                         Turn around time
P1                                                  4 - 0                                                             4ms
P2                                                  7 - 1                                                             6ms
P3                                                  8 - 2                                                             6ms
P4                                                  10 - 3                                                           7ms
P5                                                  15 - 4                                                           11ms

Implementation of FCFS in C++



OUTPUT:


First Come First Serve Scheduling



Post a Comment (0)
Previous Post Next Post