in reply to Forking child processes.
plus$pm->run_on_finish(sub { my ($pid, $exit_code, $ident) = @_; my ($action, $host) = $ident =~ /^(.*?) on (.*)/s; printf "run_on_finish: %s (pid: %s exited with code: %s\n", $ident, $pid, $exit_code; insert_into_db(\$dbh, $host, $action, $exit_code); });
orfor my $host (@hosts) { if (!$pm->start("cmd1 on $host")) { exec(@cmd1, $host); print(STDERR "cmd1 exec failed: $!\n"); _exit($!); } if (!$pm->start("cmd2 on $host")) { exec(@cmd2, $host); print(STDERR "cmd2 exec failed: $!\n"); _exit($!); } }
for my $host (@hosts) { for ( [ cmd1 => \@cmd1 ], [ cmd2 => \@cmd2 ], ) { my ($action, $cmd) = @$_; $pm->start("$action on $host") and next; exec(@$cmd, $host); print(STDERR "$action exec failed: $!\n"); _exit($!); } }
I guess you could also pass a two element array for ident instead of building and splitting a string.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Forking child processes.
by sojourn548 (Acolyte) on Sep 16, 2009 at 16:40 UTC | |
by ikegami (Patriarch) on Sep 16, 2009 at 17:26 UTC | |
by sojourn548 (Acolyte) on Nov 06, 2009 at 20:29 UTC | |
by ikegami (Patriarch) on Nov 06, 2009 at 20:59 UTC | |
by ikegami (Patriarch) on Sep 16, 2009 at 21:20 UTC | |
by sojourn548 (Acolyte) on Sep 18, 2009 at 21:43 UTC | |
by sojourn548 (Acolyte) on Sep 19, 2009 at 03:32 UTC | |
by sojourn548 (Acolyte) on Sep 22, 2009 at 06:13 UTC |