I thought I understood this but maybe I don't.
When perl forks it creates an exact copy of itself with open files, same
variables,
hashes, arrays, etc.
But when a variable in one changes, do they all change?
What's wrong with how I'm trying to use the $children variable to track
whether or
not I still have processes running?
#!/usr/local/bin/perl
use strict;
use warnings;
my $pid;
my $children = 0;
my @args = (
"arg1",
"arg2",
"arg3",
"arg4",
);
foreach my $arg ( @args ) {
if ( $pid = fork() ) {
#parent
#do nothing yet
} else {
#child
$children++;
system("my_command -a $arg");
$children--;
exit;
}
} # end foreach
# didn't let children fall through, so this is in the parent process
# this is where I do lots of stuff waiting for $children to equal zero
while ( $children ) {
# gather some data from "ps" and parsing log files, etc...
}
#end of script
Thanks in advance for any insights,
Travis.
---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.