#include
#include
#include
int main()
{
char buff[10];
char tx[]=”hello wor\n”;
int fd[2],t;
pid_t pd;
printf(“\n %s”,tx);
pipe(fd);
pd = fork();
if (pd == 0 )
{
printf(“\n parent cerated : %d”,getpid());
close(fd[0]);
write (fd[1],tx,sizeof(tx));
}
else if(pd == 1)
{
printf(“\n child cerated : %d”,getpid());
close(fd[1]);
printf(“\n %s”,buff);
read(fd[0],buff,sizeof(buff));
printf(“the received string is :%s”,buff);
}
return (0);
}
well i just had a glance to ur pgm.it looks ok for me.plz mention wht kind of error u r getting.is it related with read write operation of some other prblm.
i wld suggest u to check whether system calls are correctly called with some error check condition.check whether u can print some statements inside child & parent or nt.even read & write functions returns the size of character read or written.check those values too.
my program is working now ,
it was a minor mistake
you hav made so couple of small mistakes here is your right program after modification … checkout the changes and wts going wrong in your program .
int main()
{
char buff[10];
char tx[]=”hello wor\n”;
int fd[2],t;
pid_t pd;
printf(“\n %s”,tx);
memset(buff,”,sizeof(buff));
pipe(fd);
pd = fork();
if (pd > 0 )
{
printf(” parent cerated : %d\n”,getpid());
//close(fd[0]);
write (fd[1],tx,sizeof(tx));
}
else if(pd == 0)
{
printf(“\n child cerated : %d”,getpid());
//close(fd[1]);
printf(“\n %s”,buff);
read(fd[0],buff,sizeof(buff));
printf(“the received string is :%s”,buff);
}
return 0;
}