I have the following problem. I have 24 subprocesses I wish to start on 24 different remote nodes computers. I can successfully do this using a perl fork command. However, for debugging purposes I wish to see the commands that the child processes are issued to start. I try and do this by issuing a simple 'print' statement with the issued command to a log file. The problem is this, I do 24 forks, yet a maximum of 18 commands are printed to the log file... I thought there should be 24 commands printed, since I do 24 forks! Even more surprising to me, is that all 24 processes still run correctly.
What is going on? Here is my forking code, you can see the 'print' statement in the 'child process' section:
Any ideas or suggestions would be greatly appreciated! Thanks!if($phase==1) # Setup phase { # set up child signal handler $SIG{'CHLD'} = \&$sub; $|++; %fhlist; %fhlist2; %fhlist3; } elsif($phase==2) # Spawn the jobs phase { # Create an anonymous file handle $pid = fork(); if($pid < 0 or not defined $pid) { print LOG "$#-> Can't fork! Bad kernel!"; close LOG; die "$#-> Can't fork! Bad kernel!"; } elsif($pid == 0) { # child process print JUNKD "/usr/bin/rsh $proc $cmd\n"; system("/usr/bin/rsh $proc $cmd"); exit(0); } else { # Parent process, toss child file handle into the hash and move +on with # our lives. $fhlist{"$pid"} = $nt; $fhlist2{"$pid"} = $mc; $fhlist3{"$pid"} = $um; } } elsif($phase==3) # Wait till the children are done phase { while(1) { @kl = keys(%fhlist); if($#kl >= 0) { # mo' to do... sleep($sleep); } else { last; } } }
In reply to Cannot print child process command during fork by whatwhat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |