Last updated on June 13th, 2020 at 08:36 pm
First Come First Served (FCFS) CPU Scheduling Algorithm in C++ with Explanation:
CPU gets a lot of processes to handle. The problem is shortening the waiting time for a process to reach CPU and get processed. Now consider a CPU and also consider a list in which the processes are listed as follows,
Arrival
|
Process
|
Burst Time
|
0
|
1
|
3
|
1
|
2
|
2
|
2
|
3
|
1
|
Process-1
|
Process-1
|
Process-1
|
Process-2
|
Process-2
|
Process-3
|
0s
|
1s
|
2s
|
3s
|
4s
|
5s
|
| Process-1
|
| Process-2
|
| Process-3
|
|
|
0
|
3
|
5
|
6
|
Process-2 at 3s. So process-2 waited for 2s.
Process-1
|
Process-1
|
Process-1
|
Process-2
|
Process-2
|
Process-3
|
0s
|
1s
|
2s
|
3s
|
4s
|
5s
|
Process-1
|
Process-1
|
Process-1
|
Process-2
|
Process-2
|
Process-3
|
0s
|
1s
|
2s
|
3s
|
4s
|
5s
|
The Program:
Input
You will ask the user for the number of processes. Then for each process you will take its Process Number, Arrival Time and its Burst time. You don’t have to worry, the number of processes wont be more than 5 or 6, Arrival time of a process can only be equal or greater than the arrival time of its previous process and Process will be entered as a serial number, so no problem.
Output:
In the output you will have to print out the shortened time-line we showed you above. For example, if the input is as follows,
Arrival
|
Process
|
Burst Time
|
0
|
1
|
3
|
1
|
2
|
2
|
2
|
3
|
1
|
| Process-1
|
| Process-2
|
| Process-3
|
|
|
0
|
3
|
5
|
6
|
You can also print out the time-line vertically if you want (that’s what I have done, see the output of my program)
Process
|
Arrival
|
Finish
|
Total
|
Wait
|
1
|
0
|
2
|
3
|
0
|
2
|
1
|
4
|
2
|
2
|
3
|
2
|
5
|
1
|
3
|
Exception:
One exception is that, I said “Arrival time of a process can only be equal or greater than the arrival time of its previous process”. So take a look at the following list of process,
Arrival
|
Process
|
Burst Time
|
0
|
1
|
3
|
55
|
2
|
2
|
60
|
3
|
1
|
In the program u should sort Arrival time so that your program will work even if i input in wrong order
In this program, I wasn't in need to do that as in real case, the arrival time will never come unsorted. However, thanks for suggestion.
Available codes for HTML ?
You want code of this solution in HTML !!!!!!!!!!!!!!!!!!!!!
i need the code plz..thanks
sorry, i am supposed to describe and inspire, not to distribute work.
Yes bro..can u giv me the code of the fcfs scheduler in html..?
Nor I can give you the code in HTML (!) neither in any other language 🙁
sorry ,using this fcfs description i am get confuse how the actually fcfs works
Simply, the processor works on the process that arrives first, and so on. It completes one process and then moves to the next one.
Hi, how did you do the code for the idle time?