Re: subprocesses lifecycle
- From: "C.DeRykus" <ced@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 29 Aug 2008 05:19:55 -0700 (PDT)
On Aug 28, 10:43 am, Hans Mulder <han...@xxxxxxxxx> wrote:
Matthieu Imbert wrote:
But it does not explain why in your example the parent script returns
immediately when calling die, while in my case the parent script waits
for children to end before returning. I thought that this could be
related to the way you create child processes (with fork), whereas i
create then with open. But this little test script returns immediately:
perl -e '
open (CHILD,"sleep 30 |");
die "byebye";
'
By contrast, if I do this:
perl -e '
open my $child ,"sleep 30 |";
die "byebye";
'
, then I have to wait 30 seconds.
It looks like when my $child goes out of scope, perl closes the handle
and this implies waiting for the child to finish and then setting $?.
I would have thought your example should behave the same, but it doesn't
(not on my machine anyway).
Perhaps you need a double fork. That is, your child could fork and then
the original child exits immediately, letting the grandchild to the real
work. That way, your script won't have to wait when it decides to close
the $child handle.
What you'd really want, is a way to tell C<open> that you don't want
C<close> to wait for this child. As far as I know, there is currently
no simple way to achieve that.
Wouldn't backgrounding the task
accomplish that:
open my $fd, "/some/task & |"
or die...
However, child subprocesses would then need to be foregrounded with
SIGCONT if the parent wants to kill them before exiting.
--
Charles DeRykus
.
- Follow-Ups:
- Re: subprocesses lifecycle
- From: Eric Pozharski
- Re: subprocesses lifecycle
- References:
- subprocesses lifecycle
- From: Matthieu Imbert
- Re: subprocesses lifecycle
- From: Eric Pozharski
- Re: subprocesses lifecycle
- From: Matthieu Imbert
- Re: subprocesses lifecycle
- From: Hans Mulder
- subprocesses lifecycle
- Prev by Date: Re: [Q] How to seach an unmapped network drive
- Next by Date: FAQ 7.4 How do I skip some return values?
- Previous by thread: Re: subprocesses lifecycle
- Next by thread: Re: subprocesses lifecycle
- Index(es):
Relevant Pages
|