#!/usr/bin/perl use warnings; use strict; use Parallel::ForkManager; my $max_forks = 10; my $fork = new Parallel::ForkManager($max_forks); # on start callback $fork->run_on_start( sub { my $pid = shift; } ); # on finish callback $fork->run_on_finish( sub { my ($pid, $exit, $ident, $signal, $core) = @_; if ($core){ print "PID $pid core dumped.\n"; } } ); # forking code for my $client (1..33){ $fork->start and next; do_something($client); sleep(2); $fork->finish; } sub do_something { my $client = shift; print "$client\n"; } $fork->wait_all_children; #### wait_for_available_procs( $n ) Wait until $n available process slots are available. If $n is not given, defaults to 1.