Re: subprocesses lifecycle



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
.



Relevant Pages

  • Re: trying to understand fork and wait
    ... old habits based on learning to script in REXX on the ... > the child reads it. ... situation for me (drop through to bottom/go back to top of loop). ... just to keep a hold of the exit code. ...
    (comp.lang.perl.misc)
  • Re: Questions about perl daemons with child processes and open files / signals
    ... running as daemon which launch a child process. ... I need to run a perl script as a daemon. ... tcpdump output, but I decided to use a pipe ... the parent process. ...
    (comp.lang.perl.misc)
  • Heirarchical path to the net
    ... traced the path of a net from child or leaf cell to the parent. ... script was run and it used .sch files(we use Calibre, ... Why the script traced up is because some signals have fan outs. ... hiCreateAppForm( ...
    (comp.cad.cadence)
  • Re: New Security Features, Please Comment
    ... then call setuid/gid and then launch the script ... language. ... The idea is to not allow the child to change its own uid, ...
    (Linux-Kernel)
  • Re: ("Scripting.Dictionary") buffer
    ... RAM I managed to populate a dictionary object with 18,000 Distinguished ... My test script was slow, ... ' Sub to enumerate users in OU/Container and child containers. ...
    (microsoft.public.scripting.vbscript)