- FCFS is a Non-Preemptive CPU scheduling algorithm, so the winner process will not release the CPU and other resources by itself until it finishes its complete execution.
- Not an ideal technique for time-sharing systems.
- FCFS is not very efficient as compared to the other scheduling algorithms.
- If the process first arrived is a big process with a high burst time, then other processes with less burst time need to wait.
- The average wait time is high.
- Easy to implement.
- Easy to understand.
- FCFS algorithm is the simplest than all other CPU scheduling algorithms.
- Very Easy to program.
Process | Burst Time | Arrival |
P1 | 4 | 2nd |
P2 | 2 | 3rd |
P3 | 8 | 1st |
P4 | 3 | 4th |

Process | Waiting Time |
P1 | 8 |
P2 | 12 |
P3 | 0 |
P4 | 14 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#include<iostream> using namespace std; int main() { int n,BurstTime[50],WaitingTime[50],TurnAroundTime[50],AverageWaitingTime=0,AverageTurnAroundTime=0,i,j; cout<<"Enter total number of processes to demonstrate, Total processes can be from 0 to 50"<<endl; cin>>n; cout<<"\nEnter Burst Time for the process: \n"; for(i=0;i<n;i++) { cout<<"Process["<<i+1<<"]:"; cin>>BurstTime[i]; } WaitingTime[0]=0; //waiting time of first process is initiliazed with 0 // waiting time for each process for(i=1;i<n;i++) { WaitingTime[i]=0; for(j=0;j<i;j++) WaitingTime[i]+=BurstTime[j]; } cout<<"\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time"; //turnaround time calculation for each process for(i=0;i<n;i++) { TurnAroundTime[i]=BurstTime[i]+WaitingTime[i]; AverageWaitingTime+=WaitingTime[i]; AverageTurnAroundTime+=TurnAroundTime[i]; cout<<"\nProcess["<<i+1<<"]"<<"\t\t"<<BurstTime[i]<<"\t\t"<<WaitingTime[i]<<"\t\t"<<TurnAroundTime[i]; } AverageWaitingTime/=i; AverageTurnAroundTime/=i; cout<<"\n\nAverageerage Waiting Time:"<<AverageWaitingTime; cout<<"\nAverageerage Turnaround Time:"<<AverageTurnAroundTime; return 0; } |
FCFS Process Scheduling Implementation in C++ by using Virtual Function
Let’s see the FCFS Process Scheduling Implementation in C++ by using Virtual Function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
#include<iostream> using namespace std; class display; class process { protected: int n,burst_time[15],wait_time[15],total_time[15],i,j; public: process() { n=0; i=0;j=0; } virtual void processes()=0; void input_burst_time() { cout<<"\nEnter burst Time\n"; for(i=0;i<n;i++) { cout<<"Process["<<i+1<<"]:"; cin>>burst_time[i]; } } }; class display : public process { public: void processes() { cout<<"Enter No. of processes:"; cin>>n; } void cal_wait() { wait_time[0]=0; for(i=1;i<n;i++) { wait_time[i]=0; for(j=0;j<i;j++) wait_time[i]+=burst_time[j]; } } void show() { for(i=0;i<n;i++) { total_time[i]=burst_time[i]+wait_time[i]; cout<<"\nP["<<"Process"<<"\t\t"<<"Burst Time"<<"\t\t"<<"Wait Time"<<"\t\t"<<"Total Time\n"; cout<<"\nP["<<i+1<<"]"<<"\t\t\t"<<burst_time[i]<<"\t\t\t"<<wait_time[i]<<"\t\t\t"<<total_time[i]; } } }; int main() { display obj; obj.processes(); obj.input_burst_time(); obj.cal_wait(); obj.show(); return 0; } |

FCFS Code using Inheritance of Classes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include<iostream> using namespace std; class base_class // Base Class { protected: //To be accessible in derived class int n,burst[10],wait[10],time[10],i,j; public: base_class() { n=0; i=0; j=0; } void input_burst() { cout<<"\nburst Time\n"; for(i=0;i<n;i++) { cout<<"Process["<<i+1<<"]:"; cin>>burst[i]; } } }; class child : public base_class // Derived Class { public: void processes() { cout<<"Enter No. of processes:"; cin>>n; } void cal_wait() { wait[0]=0; for(i=1;i<n;i++) { wait[i]=0; for(j=0;j<i;j++) wait[i]+=burst[j]; } } void show() { for(i=0;i<n;i++) { time[i]=burst[i]+wait[i]; cout<<"\nP["<<"Process"<<"\t\t"<<"Burst Time"<<"\t\t"<<"Wait Time"<<"\t\t"<<"Total Time\n"; cout<<"\nP["<<i+1<<"]"<<"\t\t\t"<<burst[i]<<"\t\t\t"<<wait[i]<<"\t\t\t"<<time[i]; } } }; int main() { child obj; obj.processes(); obj.input_burst(); obj.cal_wait(); obj.show(); return 0; } |
FCFS Program Using Virtual Function
Let’s see the FCFS Program Using Virtual Function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
#include<iostream> using namespace std; class display; class process { protected: int n,burst_time[15],wait_time[15],total_time[15],i,j; public: process() { n=0; i=0;j=0; } virtual void processes()=0; void input_burst_time() { cout<<"\nEnter burst Time\n"; for(i=0;i<n;i++) { cout<<"Process["<<i+1<<"]:"; cin>>burst_time[i]; } } }; class display : public process { public: void processes() { cout<<"Enter No. of processes:"; cin>>n; } void cal_wait() { wait_time[0]=0; for(i=1;i<n;i++) { wait_time[i]=0; for(j=0;j<i;j++) wait_time[i]+=burst_time[j]; } } void show() { for(i=0;i<n;i++) { total_time[i]=burst_time[i]+wait_time[i]; cout<<"\nP["<<"Process"<<"\t\t"<<"Burst Time"<<"\t\t"<<"Wait Time"<<"\t\t"<<"Total Time\n"; cout<<"\nP["<<i+1<<"]"<<"\t\t\t"<<burst_time[i]<<"\t\t\t"<<wait_time[i]<<"\t\t\t"<<total_time[i]; } } }; int main() { display obj; obj.processes(); obj.input_burst_time(); obj.cal_wait(); obj.show(); return 0; } |
FCFS using JAVA
This is the code of FCFS using JAVA.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
import java.util.*; public class FCFS { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("enter no of process: "); int n = sc.nextInt(); int processid[] = new int[n]; int arrival_time[] = new int[n]; int burst_time[] = new int[n]; int completion_time[] = new int[n]; int trunaround_time[] = new int[n]; int waiting_time[] = new int[n]; int temp; float avgwt=0,avgta=0; for(int i = 0; i < n; i++) { System.out.println("enter process " + (i+1) + " arrival time: "); arrival_time[i] = sc.nextInt(); System.out.println("enter process " + (i+1) + " brust time: "); burst_time[i] = sc.nextInt(); processid[i] = i+1; } //process are sorted keeping in view the to arrival times for(int i = 0 ; i <n; i++) { for(int j=0; j < n-(i+1) ; j++) { if( arrival_time[j] > arrival_time[j+1] ) { temp = arrival_time[j]; arrival_time[j] = arrival_time[j+1]; arrival_time[j+1] = temp; temp = burst_time[j]; burst_time[j] = burst_time[j+1]; burst_time[j+1] = temp; temp = processid[j]; processid[j] = processid[j+1]; processid[j+1] = temp; } } } // finding completion times for each process for(int i = 0 ; i < n; i++) { if( i == 0) { completion_time[i] = arrival_time[i] + burst_time[i]; } else { if( arrival_time[i] > completion_time[i-1]) { completion_time[i] = arrival_time[i] + burst_time[i]; } else completion_time[i] = completion_time[i-1] + burst_time[i]; } trunaround_time[i] = completion_time[i] - arrival_time[i] ; // turnaround time= completion time- arrival time waiting_time[i] = trunaround_time[i] - burst_time[i] ; // waiting time= turnaround time- burst time avgwt += waiting_time[i] ; // total waiting time avgta += trunaround_time[i] ; // total turnaround time } System.out.println("\npid arrival brust complete turn waiting"); for(int i = 0 ; i< n; i++) { System.out.println(processid[i] + " \t " + arrival_time[i] + "\t" + burst_time[i] + "\t" + completion_time[i] + "\t" + trunaround_time[i] + "\t" + waiting_time[i] ) ; } sc.close(); System.out.println("\naverage waiting time: "+ (avgwt/n)); // printing average waiting time. System.out.println("average turnaround time:"+(avgta/n)); // printing average turnaround time. } } |