#include
#include
#include
#include
#include
void main()
{ int buffer[10],temp[10];pid_t childpid;
int pd[2],rpd[2],n,no,j,st,i=0,k=0,num;
printf("\n enter the no of no.s(<=10)");
scanf("%d",&n);
st=pipe(pd);
if(st==-1)
{ printf("\n unable to create pipes");
exit(0);
}
st=pipe(rpd);
if(st==-1)
{ printf("\n unable to create pipes");
exit(0);
}
childpid=fork();
if (childpid==0)
{ //child
sleep(n*3);
printf("\n child process computes\n ");
close(rpd[0]);
close(pd[1]);
read(pd[0],temp,sizeof(temp));
for(i=0;i
for(j=2;j
{temp[i]=-2;break;}
}
//printf("%d",temp[i]);
}
write(rpd[1],temp,sizeof(temp));
}
else
{//parent
printf("\n parent process takes and sends nos");
close(rpd[1]);
close(pd[0]);
k=0;
while(k
printf("\nenter no. %d ",k+1);
scanf("%d",&buffer[k]);
k++;
}
write(pd[1],buffer,sizeof(buffer));
waitpid(childpid,NULL,0);
printf("\n back to parent");
read(rpd[0],buffer,sizeof(buffer));
k=0;
while(k
printf("\n %d\n ",buffer[k]);
k++;
}
}
}//end of main
#include"stdio.h"
ReplyDelete#include"sys/types.h"
#include"unistd.h"
#include"string.h"
#include"stdlib.h"