in reply to Why is SIGCHLD affecting sleep?
And let the init process clean up the defunct child. Obviously if you need the exit status of the child or if you need to keep track of which children have finished, this won't work.$SIG{CHLD} = 'IGNORE'
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 se +conds 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 ar +g } sub foo { print "*" for (1..5); }
|
|---|