Question

Let's consider the following example.

I have a parent process that creates a pipe, spawns a child and read the child's standard output using this pipe. At some point, the parent process is no longer interested in the child's output, and closes the read end of the pipe.

Apparently, if the child keeps writing, will this result in the child process receiving a SIGPIPE signal.

Question: is there a way to redirect the child's output to /dev/null so that it still keeps running and producing output, but the parent process can go on doing other things and call waitpid on the child later? Note that setting the child's SIGPIPE handler to SIG_IGN is not an option because I don't have control over the child's signal handlers.

Was it helpful?

Solution

Emulate /dev/null yourself -- fork() a new process whose job is to read and ignore the output from the child.

OTHER TIPS

Note that setting the child's SIGPIPE handler to SIG_IGN is not an option because I don't have control over the child's signal handlers.

Wrap it in a simple binary. (Even a shellscript will do btw.)

Sigpipe happens when the pipe between two component breaks.

You can ignore the sigpipe by the following

signal(SIGPIPE, SIG_IGN);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top