Skip to content

Instantly share code, notes, and snippets.

@kenelliott
Created March 25, 2013 14:20
Show Gist options
  • Save kenelliott/5237436 to your computer and use it in GitHub Desktop.
Save kenelliott/5237436 to your computer and use it in GitHub Desktop.
Parallel ForkManager
#!/usr/bin/perl
use Parallel::ForkManager;
use Data::Dumper;
$ENV{'foo'} = 'bar';
my $pm = Parallel::ForkManager->new( shift );
my $cnt = 10;
for ( 1 .. $cnt ) {
$ENV{'bat'} = 'baz';
$pm->start and next;
&do_this;
$pm->finish;
}
$pm->wait_all_children();
sub do_this {
print 'PID: '.$$.' Foo: '.$ENV{'foo'}.' Bar: '.$ENV{'bat'}."\n";
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment