## declare a pid for forking my $pid if ($fork); ## for my $node(@devices) { ## fork new process if child does not have pid if (($fork) && ($pid = fork)) { next; } elsif((defined($pid)) || (!$fork)) { ##do some exciting things ... ## explicitly exit the child process exit if ($fork); ## if forking error exit script } else { die "\n\nfound errors in forking\nError: $!\n\n"; ## end of if loop } ## wait on child processes to exit wait() if ($fork); ## end of for loop } ## exit the script exit;