gnu parallel:同步输出?

时间:2017-04-20 14:45:15

标签: bash parallel-processing synchronization gnu-parallel

我正在运行这样的gnu并行作业:

parallel program ::: 1 2 3 4 5 6 7 8 9 10 > output.txt

我想保证输出文件是有序的。也就是说,第一行对应program 1的输出,下一行对应program 2的输出,等等。

我如何保证这一点?

1 个答案:

答案 0 :(得分:2)

我认为-k选项可能是你想要的:

 --keep-order
   -k       Keep sequence of output same as the order of input.
            Normally the output of a job will be printed as soon
            as the job completes.
            Try this to see the difference:
              parallel -j4 sleep {}\; echo {} ::: 2 1 4 3
              parallel -j4 -k sleep {}\; echo {} ::: 2 1 4 3

在手册页的前一个示例中,输出为1 2 3 4,而后者确实生成2 1 4 3