# nohup does not really protect program from first SIGHUP signal?



## hk7 (Jan 27, 2018)

source code from /usr/src/usr.bin/nohup/nohup.c:

```
(void)signal(SIGHUP, SIG_IGN);

  execvp(*argv, argv);
```
we can see that `nohup` first registers  SIGHUP handler to SIG_IGN, but it  then `execvp` the program we specify. which will clear all manual registered signal handlers.


----------



## tobik@ (Jan 27, 2018)

hk7 said:


> which will clear all manual registered signal handlers.


I don't think that's true.

exec(3)


> Signals set to be ignored in the calling process are *set to be ignored in the new process*.  Signals which are set to be caught in the calling process image are set to default action in the new process image.



signal(3)


> All caught signals may be reset to their default action by a call to the execve(2) function; *ignored signals remain ignored*.


----------



## hk7 (Jan 27, 2018)

Don't know why, but this will kill `vim`.
on terminal 1: `nohup vim`
on terminal 2: `killall -HUP vim`


----------



## mrclksr (Jan 27, 2018)

hk7 said:


> Don't know why, but this will kill  vim.
> on terminal 1:  nohup vim
> on terminal 2:  killall -HUP vim


[FONT=Courier New]SIGHUP[/FONT] is set to be ignored by `nohup`, but if the process `nohup` executes installs a signal handler for [FONT=Courier New]SIGHUP[/FONT], it will receive this signal.


----------

