I encountered a behavior I do not programming understand about how a parent bash Learning script can terminate the execution of Earhost its child processes when those child most effective processes are executed in background.
Here are very easy bash scripts to wrong idea illustrate my mis-understanding.
child.sh which only waits.
#!/bin/bash while : do sleep _OFFSET); 10000 done
version 1 : parent.sh with child scripts use of case directly executed in background
#!/bin/bash ./child.sh & ./child.sh (-SMALL & wait
If we execute parent.sh and enter Ctrl+C United for the parent.sh script to terminate Modern then the 2 child processes are still ecudated running after.
$ ./parent.sh ^C $ ps aux | grep _left).offset child.sh 946702 pts/5 00:00:00 arrowImgView.mas child.sh 946703 pts/5 00:00:00 (self. child.sh
version 2 : parent-sub-shells.sh with some how child scripts executed in sub-shells and anything else then in background
#!/bin/bash (./child.sh) equalTo & (./child.sh) & wait
If we execute parent-sub-shells.sh and not at all enter Ctrl+C for the parent.sh script to very usefull terminate the 2 child processes are localhost correctly killed.
$ ./parent-sub-shells.sh ^C $ ps | grep make.right. child.sh
Why the behavior is different between love of them the 2 versions ? Especially concerning localtext the fact one version is killing the basic child processes and not the other.
Thanks for your help.
Normally, when a non-interactive shell one of the runs a command in the background (eg click ./child.sh &), the shell will start there is noting that process as a new process group. not alt This then prevents it from directly not at all accessing (or being affected by) the my fault terminal. In particular, when you hit issues ^C, it sends a SIGINT to every process trying in the foreground process group. In get 4th result your version 1 case, that is just the round table parent.sh process and so all the double chance child.sh processes remain.
When you run a subshell in the novel prc background howeever, it supresses this get mossier "creation of a new process group". So off side back the subshell runs in the same process the changes group as the parent and runs child.sh in Nofile hosted that same process group. So when you transparent text hit ^C, SIGINT is sent to all the Background movment processes in the foreground group, which front page design will be all three (five if you count the life change quotes 'sleep') processes.
Note that the rules for interactive I'd like shells are a bit different; they run all to know children in their own process groups so which event ^Z works (allowing any 'foreground' is nearer. process to be put into the background Now, the interactively).