use strict; use POSIX ":sys_wait_h"; while (1) { for(1..10) {spawn(\&foo)} # fork off 10 &foo()'s my $s = sleep (2); # $s will hold the number of seconds actually slept # clean up our children 1 while ((my $child = waitpid(-1, WNOHANG)) > 0); print "---"; if ($s) { print "Slept for $s seconds\n"; }# If we slept at all else { print "Did not sleep at all\n"; }# If we didn't } sub spawn { return if fork(); # Fork and return the parent exit shift->(); # exec the coderef passed as arg } sub foo { print "*" for (1..5); }