#include< stdio.h >
#include< conio.h >
struct job
{
char name;
int a,b,s,t,w,f,v,tl ,e,p;
}x[5];
int q[20],k=0,n,front,rear,time;
void times();
void main()
{
int i,j;
clrscr();
for(i=0;i<3;i++)
{
printf(“Enter process name arrival time,burst time, for %d”,i+1);
scanf(“%s%d%d”,&x[i].name,&x[j].a,&x[i].b);
x[i].tl=x[i].b;
x[i].e=0;
}
printf(“Enter the stomp”);
scanf(“%d”,&n);
times();
printf(“process, arrival time, burst time, start time, finish time, waiting time, turn around time\n”);
for(i=0;i<3;i++)
printf(“%c\t %d\t %d\t %d\t %d\t %d\n”, x[i].name,x[i].a,x[i].b,x[i].s,x[i].f,x[i].w,x[i].t);
getch();
}
void times()
{
int i,j;
q[k]=0;
x[0].e=1;
while(front<=rear)
{
if(x[q[front]].v==0)
{
x[q[front]].s=time;
x[q[front]].v=1;
x[q[front]].w=x[q[front]].s-x[q[front]].a;
}
else
{
x[q[front]].w=x[q[front]].w+time-x[q[front]].p;
}
if(x[front].tl
{
time+=x[q[front]].tl;
x[q[front]].tl=0;
}
else
{
x[q[front]].tl-=n;
time+=n;
}
for(j=0;j<=3;j++)
{
if(x[j].a=time&&x[j].e==0)
{
q[++k]=j;
rear++;
x[j].e=1;
}
}
if(x[q[front]].tl==0)
x[q[front]].f=time;
else
{
q[++k]=q[front];
x[q[front]].p=time;
rear++;
}
front++;
}
for(i=0;i<3;i++)
x[i].t=x[i].w+x[i].b;
}
Output:
Enter process name, arrival time, burst time for job 1 :
1 6 6
Enter process name, arrival time, burst time for job 2 :
2 6 6
Enter process name, arrival time, burst time for job 3 :
3 6 6
Enter the stamp 2
Process  arrivaltime bursttime starttime finishtime workingtime turnaroundtime
1                   0                    6                  0                14                  8                    14
2                   0                    6                  2                16                 10                 16
3                  0                    6                 4               18                  6                  13
About these ads