Perl fork() for parallel processing.

foreach (@something)

  {

  &doThis($_);

  }

#This is the cycle which helps to close finished parents and their child after run.

foreach (@pids)
  {
  my $tmp = waitpid($_, 0);
  print "Done with pid $tmp\n";
  }
 

#This is the subroutine which helps to process all the items found in @something fast in parallel.

sub doThis
{
my $param = $_[0];
my $pid = fork();

if($pid)
  {
  #parent
  push(@pids, $pid);
  }
  elsif($pid == 0)
    {

   #child
   #Here put your command/sub routine what do you like to execute
    my $status = &otherFunction($param)
    exit(0);
    }
  else
    {
    die "could not fork: $!\n";
    }
}

 

* If you want to avoid need for "waitpid", set variable: $SIG{CHLD} = 'IGNORE';