我如何检查由 GNU Parallel 并行执行的单个进程 运行 的退出代码

How can i check the exit code of individual process running in parallel executed by GNU Parallel

我在 linux shell 脚本中有一个数组。数组包含 bash shell 脚本中的命令列表。 例如:

 args =( "ls","mv /abc/file1 /xyz/file2","hive -e 'select * from something'" )

现在我正在使用 GNU parallel 在数组中执行这些命令,如下所示

parallel ::: "${args[@]}" 

我想检查单个进程完成时的状态代码。 我知道 $? 会给我失败的进程数 但我想知道单个进程的退出代码。如何捕获在 GNU 并行中执行的各个进程的退出代码?

使用 --halt 1 选项,这使得 parallel 在停止命令时退出,同时返回它的退出代码。来自 man parallel:

--halt-on-error val
--halt val
        How should GNU parallel terminate if one of more jobs fail?

        0      Do not halt if a job fails. Exit status will be the
               number of jobs failed. This is the default.

        1      Do not start new jobs if a job fails, but complete the
               running jobs including cleanup. The exit status will be
               the exit status from the last failing job.

        2      Kill off all jobs immediately and exit without cleanup.
               The exit status will be the exit status from the
               failing job.

        1-99%  If val% of the jobs fail and minimum 3: Do not start
               new jobs, but complete the running jobs including
               cleanup. The exit status will be the exit status from
               the last failing job.

--joblog日志文件

已执行作业的日志文件。以下列 TAB 分隔格式将已执行作业的列表保存到日志文件:序列号、sshlogin、开始时间(自纪元以来的秒数)、运行 时间(秒)、传输的文件中的字节数、返回的文件中的字节数、退出状态、信号和命令运行。