在多线程猛砸 [英] Multithreading in Bash

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

问题描述

我想在我的shell脚本引入多线程功能。

I would like to introduce multithreading feature in my shell script.

我有一个脚本,调用函数read_cfg()使用不同的参数。
每个函数调用都是独立的。

I have a script which calls the function read_cfg() with different arguments. Each of these function calls are independent.

这将有可能以实例这些函数调用(而不是脚本)平行。
请让我怎样才能做到这一点..?

Would it be possible to instantiate these function calls (not scripts) parallelly. Please let me how can we achieve that.. ?

推荐答案

当然,只要加入&安培; 指令后:

Sure, just add & after the command:

read_cfg cfgA &
read_cfg cfgB &
read_cfg cfgC &
wait

所有这些工作随后将在后台同时运行。可选的命令,然后将等待所有作业完成。

all those jobs will then run in the background simultaneously. The optional wait command will then wait for all the jobs to finish.

每个命令将在一个单独的进程中运行,所以它在技术上不是多线程,但我相信它可以解决你的问题。

Each command will run in a separate process, so it's technically not "multithreading", but I believe it solves your problem.

这篇关于在多线程猛砸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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