小编Glu*_*ubb的帖子

为什么我的并行命令同时打印“Starting”和“Finished”?

ls *.txt | parallel 'echo Starting on file {}; mkdir {.}; cd {.}; longCMD3 ../{} > /dev/null; echo Finished file {}'
Run Code Online (Sandbox Code Playgroud)

这个 liner 部分工作,除了 longCMD3 需要大约 3 分钟,但第一和第二个 echo 命令几乎同时打印。我试过放入

wait
Run Code Online (Sandbox Code Playgroud)

在最后的回声之前,但这没有区别。

如何确保仅在 longCMD3 完成后才打印最终回声?

这是一个例子

假设我只有 4 个内核:

ls
foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt foo6.txt 
Run Code Online (Sandbox Code Playgroud)

我的期望:

Starting on file foo1.txt
Starting on file foo2.txt
Starting on file foo3.txt
Starting on file foo4.txt
Run Code Online (Sandbox Code Playgroud)

那么 longCMD3 至少需要 2 分钟才能完成其中一个文件

Finished file foo1.txt
Starting on file foo5.txt
Run Code Online (Sandbox Code Playgroud)

但我得到的是:

Starting on file foo1.txt …
Run Code Online (Sandbox Code Playgroud)

command-line bash gnu-parallel

3
推荐指数
1
解决办法
1127
查看次数

标签 统计

bash ×1

command-line ×1

gnu-parallel ×1