如何并行执行4个Shell脚本,但我不能并行使用GNU? [英] How to execute 4 shell scripts in parallel, I can't use GNU parallel?

查看:80
本文介绍了如何并行执行4个Shell脚本,但我不能并行使用GNU?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个shell脚本dog.sh,bird.sh,cow.sh和fox.sh.这些文件中的每个文件都使用xargs并行执行4个wget,以分叉一个单独的进程.现在,我希望这些脚本本身可以并行执行.由于某些我不知道的可移植性原因,我不能使用GNU并行.有没有办法用xargs或任何其他工具来做到这一点?

I have 4 shell scripts dog.sh, bird.sh, cow.sh and fox.sh. Each of these files execute 4 wgets in parallel using xargs to fork a separate process. Now I want these scripts themselves to be executed in parallel. For some portability reason unknown to me I can't use GNU parallel. IS there a way I can do this with xargs or with any other tool.

我还可以问一下可移植性原因是什么吗?

Also can I also ask what could the portability reason be?

我是Shell脚本的新手.抱歉,如果我的问题似乎含糊不清.

I'm a total newbie to shell scripting. Sorry if my question seems cryptic.

预先感谢大家.

推荐答案

最简单的方法是使所有这四个脚本后台运行.您可以使用另一个脚本"run_parallel.sh"将它们包装起来,如下所示:

The easiest way to do this is to background all four of the scripts. You could wrap these with another script "run_parallel.sh" that looks like this:

./dog.sh &
./bird.sh &
./cow.sh &
./fox.sh &

&符以非阻塞方式使调用的进程后台运行,从而使所有这4个进程同时执行.

The ampersand backgrounds the invoked process in a non-blocking fashion causing all 4 to be executed at the same time.

作为示例,下面是一个名为"one_two_three.sh"的脚本:

As an example, here's a script called "one_two_three.sh":

echo 'One'
sleep 1
echo 'Two'
sleep 1
echo 'Three'
sleep 1
echo 'Done'

和一个包装器"wrapper.sh":

and a wrapper "wrapper.sh":

./one_two_three.sh &
./one_two_three.sh &
./one_two_three.sh &
./one_two_three.sh &
echo 'Four running at once!'

这篇关于如何并行执行4个Shell脚本,但我不能并行使用GNU?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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