apolo has asked for the wisdom of the Perl Monks concerning the following question:
sub REAPER { # don't work almost on windows while (($child = waitpid(-1,WNOHANG)) > 0) {} $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER;
use POSIX ":sys_wait_h"; $|=1; #$pid=fork(); # when i use setpriority i call a fork here and replace +below in the if sentence. #$pid1=fork(); #$pid2=fork(); #setpriority($$,0); # not implement on windows :-( #setpriority($pid,1); #setpriority($pid1,2); #setpriority($pid2,3); my %CHILD = (); sub REAPER { # don't work almost on windows while (($child = waitpid(-1,WNOHANG)) > 0) {} $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; # if i do something like $SIG{CHLD} = sub { print "it's work"; }; # well ... nothing happen, why? if (!($CHLD{1} = fork())) { # when use setpriority i replace "if (!($C +HLD{1} = fork())) {" to "if (!$pid) {" print "child 1 -> $$\n"; sleep 2; # other small thing, why this sleep don't work here and s +leep the parent process? exit; # but only for 2 seconds, if i have three sleep with 2 se +conds 2*3 = 6 seconds, # itn't it? yeah yeah i'm lost ;-( } if (!($CHLD{2} = fork())) { print "child 2 -> $$\n"; sleep 2; exit; } if (!($CHLD{3} = fork())) { print "child 3 -> $$\n"; sleep 2; exit; } # if i replace $CHILD{1} with -1... dosen't work :-( # obviusly, when i use this i don't use the signal $SIG{CHLD} # if i only put one waitpid... well don't work #waitpid $CHILD{1}, WNOHANG; # if i put wait; the script work fine #waitpid $CHILD{2}, WNOHANG; # wait; #waitpid $CHILD{3}, WNOHANG; # wait; print "parent process\n";
Edited by planetscape - added code tags and line breaks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: forks, how do that?
by zentara (Cardinal) on Jan 01, 2006 at 11:14 UTC | |
by apolo (Initiate) on Jan 01, 2006 at 22:37 UTC | |
|
Re: forks, how do that?
by xdg (Monsignor) on Jan 03, 2006 at 15:57 UTC |