问题
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?
I'm a total newbie to shell scripting. Sorry if my question seems cryptic.
Thanks in advance guys.
回答1:
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 &
The ampersand backgrounds the invoked process in a non-blocking fashion causing all 4 to be executed at the same time.
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'
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!'
来源:https://stackoverflow.com/questions/24277780/how-to-execute-4-shell-scripts-in-parallel-i-cant-use-gnu-parallel