in reply to Re: Child process dies
in thread Child process dies
use strict; use warnings; use IO::Pipe; $SIG{PIPE} = sub {exit;}; print qq{Parent PID $$\n}; my $pipeFH = IO::Pipe->new(); my $pid; if ($pid = fork) { $pipeFH->writer(); print qq{Kid is PID $pid\n}; } elsif(defined($pid)) { $pipeFH->reader(); sleep 1 for 1 .. 100; exit; } while ((my $returnPid = wait) != -1) { print qq{Kid $returnPid returned\n}; }
Maybe there is a flaw in my attempt.
Cheers,
JohnGG
Update: The flaws in my attempts were twofold. Firstly, frodo72 pointed out that the SIGPIPE would not be generated until the child process tried to do I/O on the pipe that had been closed at the other end because the parent had been killed. Secondly, it appears that IO::Pipe is somehow consuming the SIGPIPE before the child sees it so the child carries on oblivious to it's parent's death. Again, frodo72 discovered this by refactoring my code to use pipe instead of IO::Pipe.
frodo72 ++ and thanks for all the help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Child process dies
by polettix (Vicar) on Jan 05, 2007 at 19:41 UTC | |
by johngg (Canon) on Jan 05, 2007 at 20:11 UTC | |
by polettix (Vicar) on Jan 05, 2007 at 23:58 UTC |