从GNU并行获取退出状态值

从GNU并行获取退出状态值

本文介绍了从GNU并行获取退出状态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的Perl包装器并行执行命令,保存STDOUT和STDERR到/tmp文件:

The Perl wrapper below executes commands in parallel, saving STDOUTand STDERR to /tmp files:

open(A,"|parallel");
for $i ("date", "ls", "pwd", "factor 17") {
  print A "$i 1> '/tmp/$i.out' 2> '/tmp/$i.err'\n";
}
close(A);

如何从各个命令获取退出状态值?

How do I obtain the exit status values from the individual commands?

推荐答案

要获取各个作业的存在状态,parallel将需要在某处写入信息.我不知道是否这样做.如果没有,您可以自己做.

To get the exist status of the individual jobs, parallel would need to write the info somewhere. I don't know if it does or not. If it doesn't, you can do that yourself.

my %jobs = (
   "date"   => "date",
   "ls"     => "ls",
   "pwd"    => "pwd",
   "factor" => "factor 17",
);

open(my $parallel, "|parallel");
for my $id (keys(%jobs)) {
   print $parallel
      $jobs{$id}
      ." 1> '/tmp/$id.out'"
      ." 2> '/tmp/$id.err' ; "
      ."echo \$?"
      ." > '/tmp/$id.exit'\n";
}

close($parallel);

my $exit_status = $? >> 8;
if ($exit_status >= 255) {
    print("Failed\n");
} else {
    printf("%d failed jobs\n", $exit_status);
}

for my $id (keys(%jobs)) {
    ...grab output and exit code from files...
}


更新:我去安装了parallel.


Update: I went and installed parallel.

它有一个名为--joblog {file}的选项,该选项会生成带有退出代码的报告.如果要将其输出到STDOUT,它将接受-作为文件名.

It has an option called --joblog {file} which produces a report with exit codes. It accepts - for file name if you want it to output to STDOUT.

请注意,parallel无法通过信号识别异常死亡,因此,--joblog报告中不包括此异常.使用我在上面发布的解决方案,丢失的.exit文件将指示异常死亡. (不过,您必须首先确保它不存在.)

Note that parallel doesn't recognise abnormal death by signal, so this is not included in the --joblog report. Using the solution I posted above, a missing .exit file would indicate an abnormal death. (You must make sure it doesn't exist in the first place, though.)

这篇关于从GNU并行获取退出状态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:56