Re: subprocesses lifecycle
- From: "C.DeRykus" <ced@xxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 27 Aug 2008 04:32:13 -0700 (PDT)
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
.
- References:
- subprocesses lifecycle
- From: Matthieu Imbert
- subprocesses lifecycle
- Prev by Date: Re: Huge perl scripts collection of any kinds for free
- Next by Date: FAQ 8.1 How do I find out which operating system I'm running under?
- Previous by thread: subprocesses lifecycle
- Next by thread: Re: subprocesses lifecycle
- Index(es):
Relevant Pages
|