spaz has asked for the wisdom of the Perl Monks concerning the following question:
Fellow Monks,
In one of my scripts I start up several child processes as follows
If I were to build up a list of PID's, how could I wait for them all to exit, and if they don't exit after a certain amount of time, kill them?
I've looked at perlipc and wait but I'm getting kind of confused about reaping and when to handle it.
Could I use something like
-- Dave
In one of my scripts I start up several child processes as follows
My question is this:foreach $item ( @array ) { if( $pid = fork ) { print "Forking off to $pid\n"; } elsif( defined $pid ) { &proprietary_function( $item ); print "Done with function\n"; exit; } else { die "Can't fork: $!"; } }
If I were to build up a list of PID's, how could I wait for them all to exit, and if they don't exit after a certain amount of time, kill them?
I've looked at perlipc and wait but I'm getting kind of confused about reaping and when to handle it.
Could I use something like
And then changesub REAPER { my $waitedpid = wait; $SIG{CHLD} = \&REAPER; }
Toif( $pid = fork ) { print "Forking off to $pid\n";
?if( $pid = fork ) { $SIG{CHLD} = \&REAPER; print "Forking off to $pid\n";
-- Dave
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Waiting..
by TheoPetersen (Priest) on Feb 23, 2001 at 03:10 UTC | |
Re: Waiting..
by mikfire (Deacon) on Feb 23, 2001 at 03:35 UTC | |
Re: Waiting..
by merlyn (Sage) on Apr 16, 2001 at 21:33 UTC |
Back to
Seekers of Perl Wisdom