when pipe writer ignores SIGPIPE and other signals...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

I ran into a program (call it XYZ) that ignores SIGPIPE and many other
signals, so doing:

open J, "$command|" or die "Could not open command [$command]: $!";
close J;

would hang my program forever (XYZ gets SIGPIPE but never exits, so my
program waits on the child PID forever).  I solved it like this:

sub cleanup
    # XYZ ignores SIGPIPE so we can't just close the pipe handle
    # we have to kill every XYZ started in a subshell by us...  annoying huh?
    my @shells = `pgrep -P $$`;
    foreach my $shell (@shells)
    chomp $shell;
    print "Killing XYZs with parent $shell\n";
    system(pkill => -9 => -f => -P => $shell => 'XYZ');
    close \*J;

Just a kill was not enough, it had to be -9.

Proc::ProcessTable was not available at the time, though I may use it

I was wondering if my approach was flawed and I am missing something
obvious, or if there's a better way to achieve this.


Site Timeline