Re: subprocesses lifecycle



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
.



Relevant Pages

  • Re: subprocesses lifecycle
    ... Matthieu Imbert wrote: ... immediately when calling die, while in my case the parent script waits ... But this little test script returns immediately: ... It looks like when my $child goes out of scope, ...
    (comp.lang.perl.misc)
  • Re: subprocesses lifecycle
    ... sleep 1;} ... about half a minute to end and die. ... But it does not explain why in your example the parent script returns ...
    (comp.lang.perl.misc)
  • 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)