Write to a dead end

I have a problem in my program that is using pipes.

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

I have 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 is fine for most messages, but when the message is very large, write to dead-end pipes.

I think the pipe might be full, but I don't know how to clean it. I tried using fsync but it didn't work.

Can anyone help me?

+2


a source to share


1 answer


You need to close the end of the read while writing. The OS will keep the data written to the pipe in the pipe buffer until all processes that have the open end of the open pipe actually read what's there.



+3


a source







All Articles