Write to pipe deadlocking program

Posted by avs3323 on Stack Overflow See other posts from Stack Overflow or by avs3323
Published on 2010-05-12T01:13:04Z Indexed on 2010/05/12 1:24 UTC
Read the original article Hit count: 220

Filed under:
|

Hi,

I am having a problem in my program that uses pipes.

What I am doing is using pipes along with fork/exec to send data to another process

What I have is something like this:

//pipes are created up here

if(fork() == 0) //child process
{
  ...
  execlp(...);
}
else
{
  ...
  fprintf(stderr, "Writing to pipe now\n");
  write(pipe, buffer, BUFFER_SIZE);
  fprintf(stderr, "Wrote to pipe!");
  ...
}

This works fine for most messages, but when the message is very large, the write into the pipe deadlocks.

I think the pipe might be full, but I do not know how to clear it. I tried using fsync but that didn't work.

Can anyone help me?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pipes