如何并行使用 xargs
一个好的开始是使用 -P 4 -n 1 并行运行 4 个进程(-P 4),但给每个要运行的命令实例只一个参数(-n 1)
这些是来自 xargs 手册页 的并行使用 xargs 选项:
xargs-options.txt
-P, --max-procs=MAX-PROCS 一次最多运行 MAX-PROCS 个进程
-n, --max-args=MAX-ARGS 每个命令行最多使用 MAX-ARGS 个参数示例:
xargs-example.sh
cat urls.txt | xargs -P 4 -n 1 wget此命令将并行运行最多 4 个 wget 进程,直到 urls.txt 中的每个 URL 都被下载。这些进程将并行运行
xargs-parallel-1.txt
wget [URL #1]
wget [URL #2]
wget [URL #3]
wget [URL #4]如果你使用 -P 4 -n 2,这些进程将并行运行:
xargs-parallel-2.txt
wget [URL #1] [URL #2]
wget [URL #3] [URL #4]
wget [URL #5] [URL #6]
wget [URL #7] [URL #8]使用更高的 -n 值可能会略微提高效率,因为需要初始化的进程更少,但如果传递多个参数,它可能不适用于某些命令。
Check out similar posts by category:
Linux
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow