#!/usr/bin/perl use strict; use warnings; use Proc::Queue 'waitpids', size => 4, debug => 1; my @pids; foreach ( 1 .. 10 ) { my $f = fork; if ( defined($f) and $f == 0 ) { print "-- I'm a forked process $$\n"; sleep rand 5; print "-- I'm tired, going away $$\n"; exit(0); } push @pids, $f if defined $f; } waitpids(@pids); print "--- FINISHED\n";