Issue
As far as I know, nohup
can keep process running without caring about terminal's exit. But I found that when I run a process in background (without nohup
) using ampersand(&
) in the end, then exit from the terminal, I can still find the process running in the machine.
Here is an simple example; I run the below command and then exit the terminal:
ping localhost &
But, I found the "ping" process still running in the machine, even though I did not use nohup
here. Am I misunderstanding nohup
's real usage?
Solution
the reason you are seeing your process still running after logging off from your session is that probably your shell doesn't send a sighup at logoff. You can confirm that by running:
shopt | grep hupon
I assume it will return something like huponexit off
...
It's not guaranteed for every Linux/shell to do that, so in order to stay safe and have your script portable, I suggest using nohup
. E.g.
nohup ping localhost &
To confirm you can also enable huponexit
, by running
shopt -s huponexit
Then run your command without nohup
, logoff/exit the shell and check if your process is still running.
Answered By - Naytzyrhc