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.

1
  • nohup itself is the child process Commented Nov 26, 2018 at 22:24

1 Answer 1

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.

5
  • 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
    Commented Nov 26, 2018 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. Commented Nov 26, 2018 at 22:13
  • Is it that way only for implementing nohup?
    – Tim
    Commented Nov 26, 2018 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. Commented Nov 26, 2018 at 22:23
  • Thanks. Guru Stephen, may I call your attention to unix.stackexchange.com/questions/484344/…
    – Tim
    Commented Nov 27, 2018 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .