0% found this document useful (0 votes)
61 views

Fcfs Scheduling Algorithm

This document describes the FCFS (First Come First Serve) CPU scheduling algorithm. It includes functions to get process data like name, burst time, and arrival time. It then sorts the processes by arrival time and calculates waiting time, turnaround time, average waiting time, and average turnaround time. The main steps are getting the data, sorting by arrival time, calculating times, and generating a Gantt chart showing the schedule.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views

Fcfs Scheduling Algorithm

This document describes the FCFS (First Come First Serve) CPU scheduling algorithm. It includes functions to get process data like name, burst time, and arrival time. It then sorts the processes by arrival time and calculates waiting time, turnaround time, average waiting time, and average turnaround time. The main steps are getting the data, sorting by arrival time, calculating times, and generating a Gantt chart showing the schedule.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

FCFS SCHEDULING ALGORITHM

#include<stdio.h>
#include<conio.h>
#include<string.h>
int n,at[20],wt[20],bt[20],tt,ttt,twt;
float awt,att;
char pname[20][20],c[20][20];
int getdata();
int calculate();
int gnattchart();
int fcfs();
int getdata()
{
int i;
printf("\t\t FCFS SCHEDULING ALGORITHM\n\n");
printf("Enter the no of process:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
printf("Enter the process name:");
scanf("%s",&pname[i]);
printf("Enter burst time for process %s:",pname[i]);
scanf("%d",&bt[i]);
printf("Enter arrival time for process %s:",pname[i]);
scanf("%d",&at[i]);

printf("\n");
}
}
int gnattchart()
{
int i;
printf("\n\t\t\t Gnatt chart");
printf("\n------------------------------------------------------\n");
for(i=1;i<=n;i++)
printf("| \t %s \t",pname[i]);
printf("|\t\n");
printf("\n------------------------------------------------------\n");

for(i=1;i<=n;i++)

printf("%d\t\t",wt[i]);
printf("%d",wt[n]+bt[n]);
}
int calculate()
{
int i;

wt[1]=0;
for(i=2;i<=n;i++)
{
wt[i]=wt[i-1]+bt[i-1];
}

for(i=1;i<=n;i++)
{
twt=twt+(wt[i]-at[i]);
ttt=ttt+((wt[i]+bt[i])-at[i]);
}
awt=(float)twt/n;
att=(float)ttt/n;
printf("\n process\t burst time \tarrival time\n");
for(i=1;i<=n;i++)
{
printf("%s\t\t%d\t\t%d\t",pname[i],bt[i],at[i]);
printf("\n");
}

printf("\naverage waiting time:%f ms\n",awt);


printf("\naverage turn around time :%f ms\n\n",att);
}
int fcfs()
{
int i,j,temp,temp1;
ttt=0;
twt=0;
for(i=1;i<=n;i++)
{
for(j=i+1;j<=n;j++)
{
if(at[i]>at[j])

{
temp=bt[i];
temp1=at[i];
bt[i]=bt[j];
at[i]=at[j];
bt[j]=temp;
at[j]=temp1;
strcpy(c[i],pname[i]);
strcpy(pname[i],pname[j]);
strcpy(pname[j],c[i]);
}}
}
calculate();
gnattchart();

}
int main()
{

getdata();
fcfs();
getch();
}

You might also like