pprindeville has asked for the wisdom of the Perl Monks concerning the following question:
and what seems to happen when the parent attempts to exit() after spawning the child, is that $pipe's destructor then wants to waitpid() on the process inside the pipe... even though there's a cloned copy of $pipe in the child process from the explicit fork(). How do I make the parent NOT call the destructor of $pipe? This is supposition, btw, as I've not had a chance to do an strace on a running instance or inspect the IO code that gets invoked in this case... Thanksmy $pipe; open($pipe, '-|', 'ip -o xfrm monitor') || die "couldn't start sub-com +mand"; my $pid = fork(); if (! defined $pid) { die "couldn't fork"; elsif ($pid > 0) { # write $pid to .pid file cleanup(); exit(0); ## problem happens HERE } ## now in sub-process close(STDIN); close(STDOUT); close(STDERR); ... while (my $line = <$pipe>) { ... } close($pipe); cleanup2(); exit(0);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What happens to a '-|' (pipe) file handle across a fork()? (misfeature)
by tye (Sage) on Nov 07, 2015 at 04:55 UTC | |
by pprindeville (Novice) on Nov 08, 2015 at 21:11 UTC | |
by Anonymous Monk on Nov 08, 2015 at 21:40 UTC | |
|
Re: What happens to a '-|' (pipe) file handle across a fork()?
by shmem (Chancellor) on Nov 07, 2015 at 01:00 UTC | |
by pprindeville (Novice) on Nov 08, 2015 at 21:08 UTC | |
by shmem (Chancellor) on Nov 08, 2015 at 21:31 UTC | |
by pprindeville (Novice) on Nov 09, 2015 at 04:12 UTC | |
by shmem (Chancellor) on Nov 10, 2015 at 11:13 UTC |