First come - First served (FCFS), is the simplest scheduling algorithm. FIFO simply queues processes according to the order they arrive in the ready queue. In this algorithm, the process that comes first will be executed first and next process starts only after the previous gets fully executed.
Terminologies Used in CPU Scheduling
- Arrival Time: The time at which the process arrives in the ready queue.
- Completion Time: The time at which the process completes its execution.
- Turn Around Time: Time Difference between completion time and arrival time. Turn Around Time = (Completion Time - Arrival Time)
- Waiting Time (W. T): Time Difference between turnaround time and burst time. CPU Burst time is the overall CPU time a process needs.
- Waiting Time = (Turn Around Time - Burst Time).
In this example, we have assumed the arrival time of all processes is 0, so turnaround and completion times are the same.
👁 Image
Implementation
Input : Processes along with their burst time (bt).
Output : Waiting time, turnaround time for all processes.
- As first process that comes need not to wait so waiting time for process 1 will be 0 i.e. wt[0] = 0.
- Find waiting time for all other processes i.e. for process i:
wt[i] = bt[i-1] + wt[i-1] . - Find turnaround time = waiting_time + burst_time for all processes.
- Find average waiting time = total_waiting_time / no_of_processes.
- Similarly, find average turnaround time =
total_turn_around_time / no_of_processes.
Code to Implement the Algorithm
Output:
Processes | Burst Time | Waiting Time | Turn-around Time |
|---|
1 | 10 | 0 | 10 |
|---|
2 | 5 | 10 | 15 |
|---|
3 | 8 | 15 | 23 |
|---|
Average waiting time = 8.33333
Average turn around time = 16
Implementation Using OOPS
PID | AT | BT | CT | TAT | WT |
|---|
0 | 0 | 10 | 10 | 10 | 0 |
|---|
1 | 10 | 5 | 15 | 5 | 0 |
|---|
2 | 15 | 8 | 23 | 8 | 0 |
|---|
Avg_turnaround:7.666666666666667
Avg_Waitingtime:0.0