I learn the difference between nohup
and &
from What's the difference between nohup and ampersand
Based on the following answers,
There is no difference between these launching methods when the shell is configured in a way where it does not send SIGHUP at all. https://stackoverflow.com/a/58691817
In case you're using bash, you can use the command shopt | grep hupon to find out whether your shell sends SIGHUP to its child processes or not. If it is off, processes won't be terminated, https://stackoverflow.com/a/15595391
I learn that if shopt | grep hupon
is off, then nohup ./foo.sh &
and ./foo.sh &
would be still running after closing the bash sessions.
Indeed, both are running when I check the status via ps -ef | grep foo.sh
.
However, the behaviors are different when I move to tmux sessions. Firstly, shopt | grep hupon
is also off in tmux sessions. But the result is that only nohup ./foo.sh &
can keep running after killing the tmux session.
There should be something different between the tmux session and the bash session, which causes the above different behaviors. Could anyone explain it or give some hints?