我怎么能并行运行命令的列表? [英] How can I run a list of commands in parallel?

查看:85
本文介绍了我怎么能并行运行命令的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含了我想要运行的命令行的文件。此文件包含大约2,000行。

I have a file containing command lines that I want to run. This file contains around 2,000 lines.

我可以有8个核心。是否有可能来解析文件和启动8进程,然后执行从每当节目之一完成的文件,另一个呢?我想,这样下去,直到达到文件结尾。

I have 8 cores available. Is it possible to parse the file and start 8 processes, then execute another one from the file whenever one of the programs finishes? I want this to continue until the end of file is reached.

推荐答案

您可以使用的的xargs 的在文件中读取,同时限制的最大进程数可用内核的数量。例如:

You can use xargs to read in the file, while limiting the maximum number of processes to the number of available cores. For example:

cores=$(fgrep -c processor /proc/cpuinfo)
xargs --arg-file=/tmp/foo \
      --max-procs=$cores  \
      --replace \
      --verbose \
      /bin/sh -c "{}"

这篇关于我怎么能并行运行命令的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆