Unix & Linux
bash sighup
Updated Fri, 23 Dec 2022 04:45:42 GMT

Why does huponexit not work in the following?


Bash manual says

If the huponexit shell option has been set with shopt (see Section 4.3.2 [The Shopt Builtin], page 62), Bash sends a SIGHUP to all jobs when an interactive login shell exits.

Why does huponexit not work in the following?

In one interactive shell

$ shopt -s huponexit
$ sleep 4321 &
[1] 13816
$ exit

Then in the other shell

$ ps -j 13816
  PID  PGID   SID TTY      STAT   TIME COMMAND
13816 13816 13728 ?        S      0:00 sleep 4321

Thanks.




Solution

when an interactive login shell exits

is significant.

$ bash -l
$ shopt -s huponexit
$ sleep 120 &
[1] 24235

Then CtrlD exits (with logout, instead of exit as in your example), and

$ ps -j 24235
  PID  PGID   SID TTY      STAT   TIME COMMAND

The sleep was killed too.