Space for google add

Write the program to simulate FCFS CPU-scheduling.

Write the program to simulate FCFS CPU-scheduling. The arrival time and first CPU-burstfor different n number of processes should be input to the algorithm. Assume the fixed IO waiting time (2 units). The next CPU-burst should be generated randomly. The output should give Gantt chart, turnaround time and waiting time for each process. Also find the average waiting time and turnaround time.

 #include<stdio.h>
#include<stdlib.h>
#define MAX 10
typedef struct PROCESS
{
char name[20];
int tat,wt,at,bt,ct;
}PROCESS;
PROCESS p[MAX];
int processCount,i,j,k;
int processCount,i,j,k;
float totaltat,totalwt,avgtat,avgwt;
void sort()
{
PROCESS p1;
for(i=0;i<processCount;i++)
{
for(j=i+1;j<processCount;j++)
{
if(p[j].at < p[i].at)
{
p1=p[j];
p[j]=p[i];
p[i]=p1;
}
}

}



void readProcess()
{
printf("\nEnter the number of process : ");
scanf("%d",&processCount);
for(i=0;i<processCount;i++)
{
printf("\nEnter the process name : ");
scanf("%s",p[i].name);
printf("\nEnter the CPU arrival time : ");
scanf("%d",&p[i].at);
printf("\nEnter the Burst time : ");
scanf("%d",&p[i].bt);
}
sort();
}


void scheduleProcess()
{

int time=0,i=0;
printf("\n\n GanntChart :\n");
printf("---------------------------------------\n");
printf("|%d ",time);
while(i<processCount)
{
p[i].wt=time-p[i].at;
time=time+p[i].bt;
p[i].ct=time;
p[i].tat=p[i].bt+p[i].wt;
printf("%s ",p[i].name);
printf("%d|%d ",time,time);
totaltat+=p[i].tat;
totalwt+=p[i].wt;
i++;
}
printf("\n--------------------------------------\n\n");
avgtat=totaltat/processCount;
avgwt=totalwt/processCount;
}


void display()
{
printf("\n--------------------------------------------------------\n");
printf("Process ArrivalTime BurstTime TurnAroundTime WaitTime\n");
printf("---------------------------------------------------------\n");
for(i=0;i<processCount;i++)
printf("%s\t %d\t\t %d\t %d\t\t %d\n",p[i].name,p[i].at,p[i].bt,p[i].tat,p[i].wt);
printf("---------------------------------------------------------");
printf("\n\nTotal turn around time :%f",totaltat);
printf("\n\nTotal wait time :%f",totalwt);
printf("\n\nAverage turn around time :%f",avgtat);
printf("\n\nAverage waiting time :%f",avgwt);
}
void main()
{
readProcess();
scheduleProcess();
display();

Post a Comment

0 Comments