I'm trying to deal with a server that works as follows:
- It has a parent process
- It creates a "helper" child process to handles some special tasks
- It opens the child process with a pipe; and uses the pipe to issue commands to the child.
- It also spawns off many other child processes (the server's main goal is to execute various commands).
I would like to be able to detect when the write to the pipe to the child process fails; and issue a special notification.
Ordinarily, I would achieve that by creating a custom $SIG{PIPE}
handler in the parent process.
However, what I'm concerned with is the fact that some of the processes the parent launches to execute commands might have their own pipes open to them; and if the write to THOSE pipes fails, I'd like to simply ignore the SIGPIPE.
Q1. Is there a way for me to tell from within SIGPIPE handler, which of the open pipes threw the signal? (I know every child's PID, so PID would be fine... or if there's a way to do it via file descriptor #s?).
Q2. Could I solve the problem using local $SIG{PIPE}
somehow? My assumption is that I would need to:
- Set helper-process-specific
local $SIG{PIPE}
right before writing to that pipe - do
print $HELPER_PIPE
(this happens in only one subroutine) - Reset $SIG{PIPE} to
DEFAULT
orIGNORE
- Ensure that these 3 actions are within their own block scope.