简体   繁体   中英

Is there a way to run a shell script as one whole task(with single PID)?

I have a shell script called run.sh. In it, I may call other shell scripts like:

./run_1.sh
./run_2.sh
.........

If I call the script by ./run.sh, I have found actually it will invoke different tasks inside the script sequentially with different PIDs(ie, run_1.sh will be a task and run_2.sh will be another task). This disables me to kill the whole group of tasks using one "kill" command or run the whole group of tasks all in background by running "./run.sh &". So is there a way to run the script just as one whole task?

  • pkill can be used for killing the children of a process, using the -P option.

     pkill -P $PID 

    where $PID is the PID of the parent process.

  • You can source the run_1.sh command so that it is executed in the same shell (This could cause side effects, since now all scripts will share the same scope) .

     source run_1.sh source run_2.sh 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM