Showing posts with label FCFS Cpu scheduling in C. Show all posts
Showing posts with label FCFS Cpu scheduling in C. Show all posts

Sunday, 28 December 2014

CPU Scheduling Algorithm - FCFS


This is a C 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 <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,bt[1000],wt[1000];
    float avgWt,totalWt=0;
    printf("Enter how many jobs ?\t");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("Enter burst time for job %d :\t",i+1);
            scanf("%d",&bt[i]);
    }
    printf("\n\nWaiting time for Job 1 : 0 units\t");
        wt[0]=0;
    for(i=1;i<n;i++)
    {
        wt[i]=bt[i-1]+wt[i-1];
        printf("\nWaiting time for Job %d : %d units \t",i+1,wt[i]);
            totalWt = totalWt + wt[i];
    }
    printf("\n\nThe total waiting time : %f\t",totalWt);
    avgWt= totalWt/n;
    printf("\n\nAverage waiting time : %f\t\n\n",avgWt);
    return 0;
}
NOTE : Assuming that all the jobs arrive at the same time.


OUTPUT :
C - CPU Scheduling Algorithm(FCFS)