Shell 脚本中的并行处理或线程 [英] Parallel processing or threading in Shell scripting

查看:35
本文介绍了Shell 脚本中的并行处理或线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 shell 中编写一个脚本,其中一个命令正在运行并需要 2 分钟.每次.此外,我们对此无能为力.但是如果我想在脚本中运行这个命令 100 次,那么总时间将为 200 分钟.这会造成一个大问题.没有人愿意等200分钟.我想要的是并行运行所有 100 个命令,以便输出将在 2 分钟内出现,或者可能需要更多时间但不要花费 200 分钟.

I am writing a script in shell in which a command is running and taking 2 min. everytime. Also, there is nothing we can do with this. But if i want to run this command 100 times in script then total time would be 200min. and this will create a big issue. Nobody want to wait for 200min. What i want is to run all 100 commands parallely so that output will come in 2min or may be some more time but dont take 200min.

如果有任何机构可以以任何方式帮助我,我将不胜感激.

it will be appreciated, if any body can help me on this in any way.

推荐答案

GNU Parallel 是你想要什么,除非你想重新发明轮子.这里有一些更详细的示例,但是差一点:

GNU Parallel is what you want, unless you want to reinvent the wheel. Here are some more detailed examples, but the short of it:

ls | parallel gzip # gzip all files in a directory

这篇关于Shell 脚本中的并行处理或线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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