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
Back to
Seekers of Perl Wisdom