When you run jobs like the example below, they're killed when you logout:
$ ./job.sh &
However, when you execute them as in the below example, redirecting stdout to
/dev/null and stderr to stdout as well as putting the job in the background, they're not killed when you log out. It's somewhat like nohup, except that the output goes to
/dev/null instead of a file.
$ ./job.sh > /dev/null 2>&1 &
I noticed that some daemons work like that and then I got curious to know the reason why they aren't killed at logout.
Can someone explain me why?
As suggested by @Patrick on his comment, I tried the same with the simplest job ever and the result is the same: the job does not die when I log out.
# while true; do sleep 1; done > /dev/null 2>&1 &  4320 # logout luis-macbook:~ luis$ luis-macbook:Downloads luis$ ssh server luis.alen@server's password: # jobs # # ps -ef | grep 4320 root 4320 1 0 01:17 ? 00:00:00 -bash
As requested by Patrick again, I did the same test without redirecting the streams and, to my surprise, the process didn't die. Now I'm completely confused... I swear I remember processes put in background dying when you logged out. Am I absolutely wrong?
# while true; do sleep 1; done &  20720 # logout luis-macbook:~ luis$ ssh server # jobs # # ps -ef | grep 20720 root 20720 1 0 23:31 ? 00:00:00 -bash