First we tried to calculate the response time and complete time
for the first process response time is equal to arrival time and complete time is equal to the sum of response time and burst time.
For next process
if arrival time is equal to the complete time of the previous process then there will be no idle time and response time is equal to the complete time of the previous process
if arrival time is greater than the complete time of the previous process then there will be the idle time and the response time will equal to the arival time of the porcess
if arrival time is less than the complete time of the previous process then there will again no idle time and response time is equal to to the complete time of the previous time
For all the above case
complete time =response+burst time
waiting time=response time-arrival time
#include<stdio.h>
#include<stdlib.h>
struct process
{
int at; //arival time
int bt; //burst time
int rt; //response time
int c; //completed time
int wt; //waiting time
int trt;
}; //structure to hold all the attributes associated with process
void display(struct process *p)//Function to display all the attributes of the process
{
int i=1;
while(1)
{
printf("Arrival time%d ",p[i].at);
printf("Burst Time%d ",p[i].bt);
printf("Response Time%d ",p[i].rt);
printf("comlete Time%d ",p[i].c);
printf("waiting Time%d ",(p[i].rt-p[i].at));
printf("\n\n");
i++;
if(i==4)
break;
}
}
void fcfs(struct process *p)//first position of the array is ignored and counting has started from index value one
{
if((p[1].at)>0)
printf("Idle 0-%d\n",p[1].at);
p[1].rt=p[1].at;
p[1].wt=0;
p[1].c=(p[1].at+p[1].bt);
int i=2;
while(1)
{
if(p[i].at==p[i-1].c)
p[i].rt=p[i-1].c;
if((p[i].at)>(p[i-1].c))
{
printf("Idle %d-%d\n",p[i-1].c,p[i].at);
p[i].rt=p[i].at;
p[i].c=p[i].rt+p[i].bt;
}
if(p[i].at<p[i-1].c)
{
p[i].rt=p[i-1].c;
p[i].c=p[i].rt+p[i].bt;
}
i++;
if(i==4)
break;
}
}
main()
{
struct process p[100];
puts("Enetr the process arival time and burst time");
int i=0;
while(1)
{
i++;
scanf("%d",&(p[i].at));
scanf("%d",&(p[i].bt));
if(i==3)
break;
}
fcfs(p);
display(p);
}
for the first process response time is equal to arrival time and complete time is equal to the sum of response time and burst time.
For next process
if arrival time is equal to the complete time of the previous process then there will be no idle time and response time is equal to the complete time of the previous process
if arrival time is greater than the complete time of the previous process then there will be the idle time and the response time will equal to the arival time of the porcess
if arrival time is less than the complete time of the previous process then there will again no idle time and response time is equal to to the complete time of the previous time
For all the above case
complete time =response+burst time
waiting time=response time-arrival time
#include<stdio.h>
#include<stdlib.h>
struct process
{
int at; //arival time
int bt; //burst time
int rt; //response time
int c; //completed time
int wt; //waiting time
int trt;
}; //structure to hold all the attributes associated with process
void display(struct process *p)//Function to display all the attributes of the process
{
int i=1;
while(1)
{
printf("Arrival time%d ",p[i].at);
printf("Burst Time%d ",p[i].bt);
printf("Response Time%d ",p[i].rt);
printf("comlete Time%d ",p[i].c);
printf("waiting Time%d ",(p[i].rt-p[i].at));
printf("\n\n");
i++;
if(i==4)
break;
}
}
void fcfs(struct process *p)//first position of the array is ignored and counting has started from index value one
{
if((p[1].at)>0)
printf("Idle 0-%d\n",p[1].at);
p[1].rt=p[1].at;
p[1].wt=0;
p[1].c=(p[1].at+p[1].bt);
int i=2;
while(1)
{
if(p[i].at==p[i-1].c)
p[i].rt=p[i-1].c;
if((p[i].at)>(p[i-1].c))
{
printf("Idle %d-%d\n",p[i-1].c,p[i].at);
p[i].rt=p[i].at;
p[i].c=p[i].rt+p[i].bt;
}
if(p[i].at<p[i-1].c)
{
p[i].rt=p[i-1].c;
p[i].c=p[i].rt+p[i].bt;
}
i++;
if(i==4)
break;
}
}
main()
{
struct process p[100];
puts("Enetr the process arival time and burst time");
int i=0;
while(1)
{
i++;
scanf("%d",&(p[i].at));
scanf("%d",&(p[i].bt));
if(i==3)
break;
}
fcfs(p);
display(p);
}
No comments:
Post a Comment