#include”header.h”
#include”declaration.h”
int main()
{
int ret,len,sum,sub,n;
int r11[2];
int r12[2];
int r21[2];
int r22[2];
int p11[2];
int p12[2];
int p21[2];
int p22[2];
struct req rq;
char br11[4],br12[4],br21[4],br22[4],bp11[4],bp12[4],bp21[4],bp22[4];
ret=pipe(r11);
ret=pipe(r21);
ret=pipe(r22);
ret=pipe(r12);
ret=pipe(p11);
ret=pipe(p21);
ret=pipe(p22);
ret=pipe(p12);
ret=fork();
if(ret == 0)
{
sprintf(br11,”%d”,r11[1]);
sprintf(br12,”%d”,r12[0]);
execl(“./rq1″,”./rq1″,br11,br12,NULL);
}
else
{
len=sizeof(struct req);
read(r11[0],&rq,len);
printf(“rq.a=%d\nrq.b=%d\nrq.c=%c\n”,rq.a,rq.b,rq.opr);
ret=fork();
if(ret == 0)
{
sprintf(bp11,”%d”,p11[0]);
sprintf(bp12,”%d”,p12[1]);
execl(“./pq1″,”./pq1″,bp11,bp12,NULL);
}
else
{
write(p11[1],&rq,len);
read(p12[0],&sum,4);
printf(“\nserver ….sum =%d\n”,sum);
}
ret=write(r12[1],&sum,4);
printf(“written for server at rq1=%d”,ret);
ret=fork();
if(ret==0)
{
sprintf(br21,”%d”,r21[1]);
sprintf(br22,”%d”,r22[0]);
execl(“./rq2″,”./rq2″,br21,br22,NULL);
}
else
{
len=sizeof(struct req);
read(r21[0],&rq,len);
printf(“rq.a=%d\nrq.b=%d\nrq.c=%c\n”,rq.a,rq.b,rq.opr);
ret=fork();
if(ret == 0)
{
sprintf(bp21,”%d”,p21[0]);
sprintf(bp22,”%d”,p22[1]);
execl(“./pq2″,”./pq2″,bp21,bp22,NULL);
}
else
{
write(p21[1],&rq,len);
read(p22[0],&sub,4);
printf(“\nserver ….sub =%d\n”,sum);
ret=write(r22[1],&sub,4);
}
}
return 0;
}
}