2

nohup is an external program. How can it change the action of SIGHUP by a child process of a shell process to be "ignore"? (in terms of some arguments when the child process invokes fork() and/or execve() on the program which follows nohup?)

Does nohup apply only to a child process of a shell process, but not to a child process of a non-shell process?

Thanks.

Tim
  • 98,580
  • 191
  • 570
  • 977

1 Answers1

5

nohup configures itself to ignore the SIGHUP signal; see for example the GNU implementation. The POSIX specification for nohup states that

At the time the named utility is invoked, the SIGHUP signal shall be set to be ignored.

As also specified by POSIX, child processes inherit ignored signals other than SIGCHLD, so any process started by nohup after it’s ignored SIGHUP will itself ignore SIGHUP.

nohup’s handling applies to any child of nohup, regardless of nohup’s parent process. nohup does not (nor can it) affect the way signals are handled by any of its parents, whether they’re shells or not.

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164
  • Thanks. "child processes inherit ignored signals other than SIGCHLD, so any process started by nohup after it’s ignored SIGHUP will itself ignore SIGHUP." Is this specified as some argument to `execve()`? – Tim Nov 26 '18 at 22:07
  • No, it’s how all the `exec` functions are specified, in all cases. There is no `exec` argument you can use to change that. – Stephen Kitt Nov 26 '18 at 22:13
  • Is it that way only for implementing nohup? – Tim Nov 26 '18 at 22:16
  • I suspect that `nohup` was taken into consideration when that part of POSIX was written, but it wasn’t the only consideration; see the rationale section on `exec` for details. – Stephen Kitt Nov 26 '18 at 22:23
  • Thanks. Guru Stephen, may I call your attention to https://unix.stackexchange.com/questions/484344/is-sighup-sent-to-this-orphaned-process-and-why-doesnt-it-terminate – Tim Nov 27 '18 at 14:50