in reply to Re: Sequential processing with fork.
in thread Sequential processing with fork.
#!/usr/bin/perl use warnings; use strict; use Parallel::ForkManager qw( ); use constant MAX_WORKERS => 10; sub work { my ($client) = @_; print("$client start...\n"); sleep(3 + int(rand(2))); print("$client done.\n"); } { my $pm = new Parallel::ForkManager(MAX_WORKERS); # Optional. $pm->run_on_finish(sub { my ($pid, $exit, $ident, $signal, $core) = @_; if ($signal) { print("Client $ident killed by signal $signal.\n"); } elsif ($exit) { print("Client $ident exited with error $error.\n"); } else { print("Client $ident completed successfully.\n"); } }); for my $client (1..33){ $pm->start($client) and next; work($client); $pm->finish(); } $pm->wait_all_children(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Sequential processing with fork.
by stevieb (Canon) on Aug 04, 2015 at 20:11 UTC |