You've got the parent/child comments the wrong way round, you may as well use exec instead of the system/exit pair, and why not catch all of those return codes from rsh?
local (%rc, $running); # turn off stdout buffering $| = 1; # catch return codes local $SIG{CHLD} = sub { $rc{wait()} = $?; --$running; }; foreach my $wks (@wkslist) { if ( my $pid = fork() ) { # parent ++$running; } else { # child print "rshing to $wks\n"; exec($rsh_cmd, $wks, "ls"); } } sleep while ($running);
I have an old snippet which you may find useful at Run some commands in parallel
Are you writing a program to execute arbitrary commands on multiple hosts at the same time? If so, check back in a day or two and I'll have the script I use posted that packs in a few features.
In reply to Re: Re: Background process using a system call
by mugwumpjism
in thread Background process using a system call
by jalebie
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |