Want multiple processes to run in the background from shell scripts

Asked 2 years ago, Updated 2 years ago, 72 views

I want to move another shell script B and C simultaneously in a different directory in shell script A.Shell scripts B, C describe running the same program group.

mkdir test1
cd test1
sh B.sh &
cd..

mkdir test2
cd test2
sh C.sh &
cd..

When written and executed in shell script A, as shown in , the program group described in shell script B runs, but the contents of shell script C do not work until it is finished.

The purpose is to shorten the time by running test1 and test2 at the same time, but I would like you to tell me how it works.

shellscript

2022-09-30 19:10

2 Answers

sh B.sh& and sh C.sh&, so they work in the background at the same time.If you are blocked from running C.sh, there may be a problem with the contents of C.sh.

I understand that B.sh and C.sh are running the same program, but isn't the program you're running not allowed to start at the same time, or is there anything else that locks the other program?


2022-09-30 19:10

Take the sh A.sh system call trace, including the child process, and you may find out where it is taking you.
※ I didn't actually run it because I don't have a mac environment.

dtruss-e-fsh A.sh


2022-09-30 19:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.