gnu 并行:同步输出?

gnu parallel: sync output?

我是 运行 像这样的 gnu 并行作业:

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

我想保证输出文件是有序的。也就是说,第一行对应 program 1 的输出,下一行对应 program 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