When a write() writes on a broken pipe, with no readers, it generates a SIGPIPE signal and the process exits.
When the write() returns -1 and errno is EPIPE?
Do I have an handler for SIGPIPE, or can I ignore it?
When a write() writes on a broken pipe, with no readers, it generates a SIGPIPE signal and the process exits.
When the write() returns -1 and errno is EPIPE?
Do I have an handler for SIGPIPE, or can I ignore it?
SIGPIPE is for situations like this:
grep "pattern" < reallyhugefile | head
grep might print millions of lines, but head only reads 10 then quits. Once head closes the read-end and quits, grep gets SIGPIPE, which kills it, forcing it to quit early instead of processing the entire file uselessly.
If you don't want your program to be killed, handle or block SIGPIPE yourself. You will start getting write-errors with errno set to EPIPE instead.
SIGPIPE the reason is close(pipe_fd[0]) when you use write() funciton .
close(pipe_fd[1]) in your child process or parent process, can solve this problem.
If you still want to ignore it. use sigaction() function.
type:
man sigaction