in reply to open pipe for input and die

Why not use the fact that a pipe-open returns the PID of the child on success?

my $child = open my $y, '/usr/bin/sleep 5|' or die "Couldn't spawn: $!/$?"; END { kill 9, $child if $child; };

Replies are listed 'Best First'.
Re^2: open pipe for input and die
by pht (Acolyte) on Dec 11, 2008 at 09:37 UTC
    Thanks. I didn't realize open will also return the pid, thus i used open2. The rest of the solution is the same though. I have a __DIE__ handler instead of an END block, because the program itself forks later on and I turn the handler off in the child.