-2

In Why is chromium-browser killed when I close the terminal despite nohup?, I wrote that in a Terminal emulator tab, I ran

$ nohup chromium-browser &

When I close the terminal tab, chromium-browser also exits. Mark replied it was because chromium-browser overrides the action of SIGHUP from ignore to default (terminate).

When I repeat the above with disown -h in place of nohup,

$ chromium-browser & disown -h

why doesn't chromium-browser terminate when I close its terminal tab? (Note that disown -h doesn't remove the chromium-browser process from the job list in the shell, so I think the chromium-browser process still receives SIGHUP from the shell)

Thanks.

Tim
  • 101,790
  • 1
    what makes you think so? run help disown in bash and read the definition of the -h option 50 times ;-) –  Nov 27 '18 at 02:03

1 Answers1

1

chromium is a bit complicated, so let's use sleep instead.

$ nohup sleep 1000 >& /dev/null &
[1] 5283

Here we have a sleep process that ignores HUP. Demonstrate by sending HUP:

$ kill -SIGHUP 5283
$ kill -SIGHUP 5283
$ kill -SIGHUP 5283

See? Nothing happens.

Let's try this again with disown:

$ sleep 1000 &
[1] 5293
$ disown -h

Here we have a sleep process that doesn't ignore HUP. Demonstrate by sending HUP:

$ kill -SIGHUP 5293
$ kill -SIGHUP 5293
bash: kill: (5293) - No such process
[1]+  Hangup                  sleep 1000

Hups, it died.

You can also do this in a new terminal after closing the old one. So apparently, closing the terminal does not send HUP after disown -h.

So why doesn't nohup chromium ignore HUP? nohup sets HUP to ignore, but chromium may choose to revert that. So nohup is super uneffective on processes that have their own ideas about signal handlers.

One way to make a process that chooses to not ignore HUP to ignore HUP anyway is to not send HUP in the first place so it won't know about the HUP and doesn't matter whether or how it handles HUP.

frostschutz
  • 48,978