我正在尝试并行多次执行长时间运行的过程。每次执行进程的参数都存储在一个以空格分隔的环境变量中。这是我要执行的人为示例:
$ echo -e 1 2 3 4 | xargs --max-procs=3 --max-args=1 --replace=% echo % is the number being processed
这是该命令的输出:
1 2 3 4 is the number being processed
为什么 max-args 似乎被忽略了?然后我尝试显式设置分隔符以提供更好的结果:
$ echo -e 1 2 3 4 | xargs -d " " --max-procs=3 --max-args=1 --replace=% echo % is the number being processed
1 is the number being processed
2 is the number being processed
3 is the number being processed
4
is the number being processed
xargs 在处理第 4 个参数时在做什么?
经过一番搜索,我确实设法几乎得到了我想要的东西。参数被正确处理,但并行性不起作用(使用此处未显示的另一个命令验证):
$ echo -e 1 2 3 4 | xargs -n 1 | xargs --max-procs=3 --max-args=1 --replace=% echo % is the number being processed
1 is the number being processed
2 is the number being processed
3 is the number being processed
4 is the number being processed
我错过了什么?