Suppose I have a shell script A.sh
whose content is:
sleep 2
echo "A: 2s"
sleep 2
echo "A: 4s"
sleep 2
echo "A: 6s"
I also have a shell script B.sh
whose content is:
sleep 2
echo "B: 2s"
sleep 2
echo "B: 4s"
sleep 2
echo "B: 6s"
sleep 2
echo "B: 8s"
sleep 2
echo "B: 10s"
When I hope to run A and B in parallel, I created a script C.sh
whose content is:
sh A.sh &
sh B.sh &
wait
The output is:
B: 2s
A: 2s
A: 4s
B: 4s
A: 6s
B: 6s
B: 8s
B: 10s
In this way A and B can run in parallel. Now I have one more requirement that is I hope to stop B when A is over. I followed the steps mentioned here and modified C.sh
to:
parallel -j2 --halt now,success=1 ::: 'sh A.sh' 'sh B.sh'
The output is:
A: 2s
A: 4s
A: 6s
parallel: This job succeeded:
sh A.sh
It seems B is not running in this way. Can anyone advise me what is the correct way to run two scripts A and B in parallel and stop B when A is over?