From: chad kellerman <[EMAIL PROTECTED]> > Helloe everyone, > I was wondering is someone can help me out with an issue with > forking. I > am trying to fork 8 process at a time. > > Here is what I have: > > <code snippet> > > #!/usr/bin/perl > use strict; > use warnings; > use lib "."; > use BACKUP; #my own module > use POSIX ":sys_wait_h"; > > my( $MAX_CHILDREN ) = "8"; > my( $CHILD_PIDS ) = "0"; > my( $maxtries ) = "7"; > my( $failure ) = "0"; > > # there are actually 100 hostIds. but you should get the point.. > my( @hostIds ) = "10.10.10.1, 10.10.10.2, 10.10.10.3 ,10.10.10.4"; > > $SIG{CHLD} = \&CHILD_COUNT($CHILD_PIDS);
Erm ... what do you think the line above means? You can either use $SIG{CHLD} = \&CHILD_COUNT; or $SIG{CHLD} = sub { CHILD_COUNT($CHILD_PIDS) }; but not what you just used. I think you should use the first and change the CHILD_COUNT to this: sub CHILD_COUNT { my $child = waitpid(-1,WNOHANG); while ($child != -1 && ($child_pids > 0 )) { $child_pids--; $child = waitpid(-1,WNOHANG); } } No need to pass the $child_pids to the function since it's a global anyway. Jenda P.S.: The line numbers look wrong. Are you sure you are looking at the same code you run? ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]