Re: subprocesses lifecycle
- From: Hans Mulder <hansmu@xxxxxxxxx>
- Date: Thu, 28 Aug 2008 19:43:27 +0200
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.
Hope this helps,
-- HansM
.
So the problem must come from something else. i have to understand why
it behaves differently in my first script (i'll try to isolate the
simplest reproducible demonstration code of the problem).
Currently, as a workaround, i added code that finds all subprocesses of
my script and sends TERM, then wait 10s, then send KILL to all of them
Matthieu
- Follow-Ups:
- Re: subprocesses lifecycle
- From: C.DeRykus
- Re: subprocesses lifecycle
- References:
- subprocesses lifecycle
- From: Matthieu Imbert
- Re: subprocesses lifecycle
- From: Eric Pozharski
- Re: subprocesses lifecycle
- From: Matthieu Imbert
- subprocesses lifecycle
- Prev by Date: Re: perl multithreading performance
- Next by Date: FAQ 7.1 Can I get a BNF/yacc/RE for the Perl language?
- Previous by thread: Re: subprocesses lifecycle
- Next by thread: Re: subprocesses lifecycle
- Index(es):
Relevant Pages
|