0% found this document useful (0 votes)
41 views3 pages

Program FIFO CPU Scheduling Alogrithm

The document describes a program that implements the First In First Out (FIFO) CPU scheduling algorithm. It takes in the process name, arrival time, and burst time as input from the user for a given number of processes. It then calculates the start time, waiting time, turnaround time, and completion time for each process using the FIFO approach. Finally, it outputs the scheduling details for each process and calculates the average waiting time and average turnaround time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views3 pages

Program FIFO CPU Scheduling Alogrithm

The document describes a program that implements the First In First Out (FIFO) CPU scheduling algorithm. It takes in the process name, arrival time, and burst time as input from the user for a given number of processes. It then calculates the start time, waiting time, turnaround time, and completion time for each process using the FIFO approach. Finally, it outputs the scheduling details for each process and calculates the average waiting time and average turnaround time.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Program FIFO CPU Scheduling Alogrithm

#include<stdio.h>
#include<string.h>
int main()
{
    char pn[10][10],t[10];
    int arr[10],bur[10],star[10],finish[10],tat[10],wt[10],i,j,n,temp;
    int totwt=0,tottat=0;
    printf("Enter the number of processes:");
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        printf("Enter the ProcessName, Arrival Time& Burst Time:");
        scanf("%s%d%d",&pn[i],&arr[i],&bur[i]);
    }
    for(i=0; i<n; i++)
    {
        for(j=0; j<n; j++)
        {
            if(arr[i]<arr[j])
            {
                temp=arr[i];
                arr[i]=arr[j];
                arr[j]=temp;
                temp=bur[i];
                bur[i]=bur[j];
                bur[j]=temp;
                strcpy(t,pn[i]);
                strcpy(pn[i],pn[j]);
                strcpy(pn[j],t);
            }
 
        }
    }
    for(i=0; i<n; i++)
    {
        if(i==0)
            star[i]=arr[i];
        else
            star[i]=finish[i-1];
        wt[i]=star[i]-arr[i];
        finish[i]=star[i]+bur[i];
        tat[i]=finish[i]-arr[i];
    }
    printf("\nPName Arrtime Burtime WaitTime Start TAT Finish");
    for(i=0; i<n; i++)
    {
        printf("\n%s\t%3d\t%3d\t%3d\t%3d\t%6d\t%6d",pn[i],arr[i],bur[i],wt[i],star[i],tat[i],finish[i]);
        totwt+=wt[i];
        tottat+=tat[i];
    }
    printf("\nAverage Waiting time:%f",(float)totwt/n);
    printf("\nAverage Turn Around Time:%f",(float)tottat/n);
    return 0;
}

Output:
Enter the number of processes:3
Enter the ProcessName, Arrival Time& Burst Time:p1 3 5
Enter the ProcessName, Arrival Time& Burst Time:p2 4 6
Enter the ProcessName, Arrival Time& Burst Time:p3 2 7

PName Arrtime Burtime WaitTime Start TAT Finish


p3 2 7 0 2 7 9
p1 3 5 6 9 11 14
p2 4 6 10 14 16 20
Average Waiting time:5.333333
Average Turn Around Time:11.333333

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int et[20],at[10],n,i,j,temp,st[10],ft[10],wt[10],ta[10];
    int totwt=0,totta=0;
    float awt,ata;
    char pn[10][10],t[10];
    //clrscr();
    printf("Enter the number of process:");
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        printf("Enter process name, arrival time& execution time:");
        //flushall();
        scanf("%s%d%d",pn[i],&at[i],&et[i]);
    }
    for(i=0; i<n; i++)
        for(j=0; j<n; j++)
        {
            if(et[i]<et[j])
            {
                temp=at[i];
                at[i]=at[j];
                at[j]=temp;
                temp=et[i];
                et[i]=et[j];
                et[j]=temp;
                strcpy(t,pn[i]);
                strcpy(pn[i],pn[j]);
                strcpy(pn[j],t);
            }
        }
    for(i=0; i<n; i++)
    {
        if(i==0)
            st[i]=at[i];
        else
            st[i]=ft[i-1];
        wt[i]=st[i]-at[i];
        ft[i]=st[i]+et[i];
        ta[i]=ft[i]-at[i];
        totwt+=wt[i];
        totta+=ta[i];
    }
    awt=(float)totwt/n;
    ata=(float)totta/n;
    printf("\nPname\tarrivaltime\texecutiontime\twaitingtime\ttatime");
    for(i=0; i<n; i++)
        printf("\n%s\t%5d\t\t%5d\t\t%5d\t\t%5d",pn[i],at[i],et[i],wt[i],ta[i]);
    printf("\nAverage waiting time is:%f",awt);
    printf("\nAverage turnaroundtime is:%f",ata);
    getch();
}

Enter the number of process:3


Enter process name, arrival time& execution time:2 5 7
Enter process name, arrival time& execution time:3 6 14
Enter process name, arrival time& execution time:4 7 12

Pname arrivaltime executiontime waitingtime tatime


2 5 7 0 7
4 7 12 5 17
3 6 14 18 32
Average waiting time is:7.666667
Average turnaroundtime is:18.666666

You might also like