C/C++ Program for First Come First Served (FCFS) Scheduling Algorithm

Here you will get C/C++ program for first come first served (fcfs) scheduling algorithm.

What is First Come First Served (FCFS) Scheduling Algorithm?

First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FIFO (First In First Out) strategy assigns priority to process in the order in which they request the processor. The process that requests the CPU first is allocated the CPU first. This is easily implemented with a FIFO queue for managing the tasks. As the process come in, they are put at the end of the queue. As the CPU finishes each task, it removes it from the start of the queue and heads on to the next task.

Also Read: C Program for Shortest Job First (SJF) Scheduling Algorithm


C Program


C++ Program


C/C++ Program for First Come First Served (FCFS) Scheduling Algorithm
Comment below if you found anything incorrect or missing in above fcfs program in C and C++.

43 thoughts on “C/C++ Program for First Come First Served (FCFS) Scheduling Algorithm

  1. Yaggesh Likhar

    It is helpful. But you can do much better. Keep trying. We are with you. JAI HIND !!

  2. nikhil

    thanks very much…..it helped me a lot.Can you please show a program for round robin scheduling algorithm?????

  3. toie

    Hi, I would like to know that how have you calculated execution time 7.661 seconds at the end. Would you let me know please. Thanks for this post and waiting for your reply.

    1. Admin Post author

      It is compiler’s inbuilt feature, this execution time also includes the time taken to enter the input.

      1. toie

        Thanks for your reply. As you said it’s compiler’s inbuilt feature. I am using visual studio and when I give F5 to run the code, it runs in command prompt. In my case this execution time doesn’t show. I guess you’ll be using different IDE. Can you please give me some information on what you are using to code and run please.

        Thanks for your time and valuable reply.

  4. Preetam

    How are you implementing FCFS algorithm without considering the arrival times of each process? The waiting time, turn around should be calculated based on the arrival time. I guess you are assuming all of the processes arrive on the same time, at the beginning, but that makes your way of implementing FCFS incorrect. Correct me if I got you wrong 🙂

  5. toie

    Thanks for your previous two replies. I would like to know that the scheduler which we are using here (FIFO) works for operating system scheduler. While in databases we do have scheduler that runs operators (here processors in FIFO) using FIFO algorithm. I am confused that are database scheduler and operating system scheduler same? If you know something about it will be very helpful to me. I will appreciate for your answer. And many thanks for your educational website.

  6. Pri

    What if there’s an idle time? How should you do the code? Thanks!

  7. chaitanya

    hi…. how can we calculate the waiting time without knowing the arrival time.. i have not observed the waiting time in the program. any kind of help appreciated.. thanks

    1. chaitanya

      i think this program is considering the completion time of previous process is same as the arrival time of the next process… am i correct..?

  8. Sanchit

    How do we make a program of FCFS having different arrival time for all other process.
    Hint: use if else condtion..

  9. Manojit Ballav

    Hello Neeraj,
    Firstly I would like to thank you for this post.
    I have noticed that the average turnaround time “avtat” which gets returned in the output is in decimal format even though you haven’t used any double datatype.
    Could you explain ?

    1. Manojit Ballav

      Hey I apologise for the mistake I overlooked the system execution time to be average time around time.

  10. Aminu Usman Jibril

    Please I need this program in Pascal as soon as possible

  11. Rizwan Afzal

    This code in C# :
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace ConsoleApplication13
    class Program
    static void Main(string[] args)
    int i, j;
    int[] burstTime = new int[5];
    int[] waitTime = new int[5];
    int[] turnaroundTime = new int[5];
    int noOfProcess;
    float avgWaitTime = 0;
    float avgTurnAroundTime = 0;
    Console.WriteLine(“Enter Total Process “);
    noOfProcess = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine(” Enter Process burst time “);
    for ( i=0; i<noOfProcess; i++)
    burstTime[i] = Convert.ToInt32(Console.ReadLine());

    Console.WriteLine(" Process Burst Time in Sequence ");
    for ( i = 0; i < noOfProcess; i++)


    waitTime[0] = 0;
    for (i=0;i<noOfProcess;i++)
    waitTime[0] = 0;
    for ( j=0;j<i;j++)
    waitTime[i] += burstTime[j];

    Console.WriteLine("Process"+"\t\t"+"Burst Time"+"\t\t"+"Waiting Time"+"\t\t"+"Turn Around Time");
    for ( i=0;i<noOfProcess;i++)
    turnaroundTime[i] = burstTime[i] + waitTime[i];
    avgWaitTime += waitTime[i];
    avgTurnAroundTime += turnaroundTime[i];

    for (i = 0; i < noOfProcess; i++)
    Console.WriteLine("P[" + i + "]" + "\t\t" + burstTime[i] + "\t\t" +"\t\t"+ waitTime[i] + "\t\t" + turnaroundTime[i]);

    avgWaitTime /= i;
    avgTurnAroundTime /= i;
    Console.WriteLine("Average Waiting Time is :"+avgWaitTime);
    Console.WriteLine("Average TurnaroundTime is:"+avgTurnAroundTime);

  12. trojan

    Hi, i would like to ask if there’s an different arrival time? Example if i put 3 processes they user will be ask to input the arrival time, burst time then it will compute the turnaround time and waiting time etc.

  13. mike

    i need help with his homework
    1. All processes are activated at time 0
    2. Assume that no process waits on I/O devices.
    3. After completing an I/O event, a process is transferred to the ready queue.
    4. Waiting time is accumulated while a process waits in the ready queue.

    Process Data:
    process goes {CPU burst, I/O time, CPU burst, I/O time, CPU burst, I/O time,…….., last CPU burst}

    P1 {4,24,5,73,3,31,5,27,4,33,6,43,4,64,5,19,2}
    P2 {18,31,19,35,11,42,18,43,19,47,18,43,17,51,19,32,10}
    P3 {6,18,4,21,7,19,4,16,5,29,7,21,8,22,6,24,5}
    P4 {17,42,19,55,20,54,17,52,15,67,12,72,15,66,14}
    P5 {5,81,4,82,5,71,3,61,5,62,4,51,3,77,4,61,3,42,5}
    P6 {10,35,12,41,14,33,11,32,15,41,13,29,11}
    P7 {21,51,23,53,24,61,22,31,21,43,20}
    P8 {11,52,14,42,15,31,17,21,16,43,12,31,13,32,15}

    Simulation completed for FCFS (see results in table below).

    CPU utilization


    Avg Wait time (WT)


    Avg Turnaround time (TT)


    Avg Response time (RT)


    SJF CPU utilization:
    FCFS CPU utilization: 82.02%
    MLFQ CPU utilization:

  14. praneeth sai

    Thank you, It is better if you take the allocating time from the user..
    do you have the code for it??

  15. trisha

    my code for fcfs:
    int main()
    int p,at[10],bt[90],i,j,wt[100],tat[100],c=0,sum=0;
    float avgwt=0;
    printf(“enter how many process:”);

    printf("enter the arrival time of process %d:",i);
    printf("enter the burst time of process %d:",i);










    printf("the average wait time is:%d\n",avgwt);

    return 0;


  16. khzama

    cpu subrit time arrivel time

    P1 6 5
    P2 5 0
    P3 3 4
    Please write this programme in C or C++

  17. akhil

    avwt and avtat must not intialised int caz they have integer value tooo. so it must be initialised using float in cpp

  18. henry

    I need help to with an assignment. I need to create multiprocesses and use different scheduling algorithms to get an optimal output. I am a beginner and a student. , Please email me if you are an expert. henryukwu55 (at) gmail

  19. bilal khan

    brother include ariaval time also in your program then it will better ok …


Leave a Reply

Your email address will not be published. Required fields are marked *