EmbLogic's Blog

this program on pipes is not wroking , can anyone tell me why ??

#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);

}

3 Responses to this program on pipes is not wroking , can anyone tell me why ??

  1. pushpa says:

    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.

  2. 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;

    }

Leave a Reply to Vaibhav Singh Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>