tags:

views:

147

answers:

2

I have the following script structure: script A opens PIPE on B, and B opens PIPE on C. So the dataflow is A->B->C. B catches SIGPIPE. Though descriptors IN and OUT are opened:

$SIG{'PIPE'} = sub {
$logger->info('caught PIPE signal.');
$logger->info("STDIN status: ".STDIN->opened());
$logger->info("STDOUT status: ".OUT->opened());
die;
};

STDIN status: 1
STDOUT status: 1

I have added IN to the $pool IO::Select and when IN is in the $pool->can_read(), I read from it with sysread(). Once a second I write to OUT with print. Also I have a listen socket in the $pool and clients can connect to it. But I only read from clients. I'm writing to OUT only.

+2  A: 

According to the Wikipedia article, it means that C has died:

On POSIX-compliant platforms, SIGPIPE is the signal sent to a process when it attempts to write to a pipe without a process connected to the other end.

Aaron Digulla
A dies after B.
Lexsys
I've updated my answer.
Aaron Digulla
But why OUT->opened() returns 1? And how can I check C is dead the other way?
Lexsys
C is dead! Long live C++!
Andomar
+2  A: 

The descriptors will be open even after the process has died. You could, for example, still read things that the program wrote before it died.

However, if you try to write to the dead program, it will throw a SIGPIPE at you.

You can check if a child process is dead by waiting on its PID:

waitpid($childpid, &WNOHANG);

If this returns 0, the child is still running.

Andomar