Re: subprocesses lifecycle



On Aug 27, 1:41 am, Matthieu Imbert <bre...@xxxxxxxxxxxxxxxxxxxxx>
wrote:
hi.

I have a perl script that forks several subprocesses at various times.

I use the open "process_name |" syntax, and then use select to read
multiple process outputs, and have a timeout on all these subprocesses.

If the timeout is reached, I want to immediately exit my script with an
error message.

Currently, when I detect the timeout, I call die "error message". the
message is displayed, but the script does not return until subprocesses
finish (this may take several minutes, depending on what the
subprocesses do).

Is there a way to force the end of all subprocesses when calling die?




Each successful pipe open will return the child process id. So,
assuming a Unix O/S, you could save child id's and then send the
signal 'TERM' serially to each child id when there's a timeout, eg,

foreach my $child (@pids) {
kill 'TERM', $child
or kill 'KILL',$child
or warn "can't signal $child\n";
}

Alternatively, 'perldoc perlipc' demo's an idiom using a negative
process id to signal an entire Unix process group, eg,

{
local $SIG{TERM} = 'IGNORE';
kill TERM => -$$;
}

--
Charles DeRykus


.



Relevant Pages

  • Re: subprocesses lifecycle
    ... subprocesses finish (this may take several minutes, ... investigate why your script attempts to collect zombies. ... writer (I intentionally say 'writer' but 'child', ... child of B) intentionally closes pipe or just ...
    (comp.lang.perl.misc)
  • subprocesses lifecycle
    ... I have a perl script that forks several subprocesses at various times. ... and have a timeout on all these subprocesses. ... Currently, when I detect the timeout, I call die "error message". ...
    (comp.lang.perl.misc)
  • Re: subprocesses lifecycle
    ... but the script does not return until subprocesses ... sleep 1;} ... investigate why your script attempts to collect zombies. ... No one can kill process which hangs in syscall till the process ...
    (comp.lang.perl.misc)
  • managing multiple subprocesses
    ... run multiple subprocesses from a python script and then wait until all ... subprocesses have completed before continuing. ... So the commands I am using are: ... Xgrid is a system for parallel computation on Mac OS X. ...
    (comp.lang.python)
  • managing multiple subprocesses
    ... run multiple subprocesses from a python script and then wait until all ... subprocesses have completed before continuing. ... So the commands I am using are: ... Xgrid is a system for parallel computation on Mac OS X. ...
    (comp.lang.python)