Friday, 16 January 2015

CPU Scheduling algorithm - FCFS (Cpp)


This is a Cpp Program which implements one of the CPU Scheduling algorithm called First Come First Served(FCFS).

FCFS is the simplest scheduling algorithm , easy to understand and implement but not as efficient as remaining scheduling algorithms as its waiting time is high.

As the name suggests , here the processes/jobs are executed on first come first serve basis.





PROGRAM :
#include <iostream>

using namespace std;

int main()
{
    int i,n,bt[1000],wt[1000];
    float avgWt,totalWt=0;
    cout << "Enter how many jobs ?\t";
    cin >> n;
    for(i=0; i<n; i++)
    {
        cout << "Enter burst time for job "<< (i+1) << "\t";
        cin >> bt[i];
    }
    cout << "\n\nWaiting time for Job 1  is : 0 units\t";
    wt[0]=0;
    for(i=1; i<n; i++)
    {
        wt[i]=bt[i-1]+wt[i-1];
        cout << "\nWaiting time for Job "<< (i+1) << "  is :" << wt[i]<<"  units \t";
        totalWt = totalWt + wt[i];
    }
    cout << "\n\nThe total waiting time : "<< totalWt;
    avgWt= totalWt/n;
    cout << "\n\nAverage waiting time : "<<avgWt << endl;
    return 0;
}

OUTPUT : 
Cpp - CPU Scheduling algorithm (FCFS)