1

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.

  • nohup itself is the child process – frostschutz Nov 26 '18 at 22:24
4

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.

| improve this answer | |
  • 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 unix.stackexchange.com/questions/484344/… – Tim Nov 27 '18 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.