I found out the nohup
tool today, and was wondering about it's implementation. Specifically, it seems like there must be a way to tell another process, or a child process, to ignore certain signals. Is there a system call, or something like that, that does this?
views:
40answers:
3
+1
A:
May the source be with you :)
Disclamer: the phrase is actually not mine, but of Marshall Kirk McKusick.
Nikolai N Fetissov
2010-08-13 22:15:25
+1. That's essentially 2 lines of code if you remove all the additional processing. :)
casablanca
2010-08-13 22:23:45
A:
Process preserves signal mask after exec call.
See sources for nohup here, for example:
http://www.opensource.apple.com/source/shell_cmds/shell_cmds-118/nohup/nohup.c
For the details on exec() call see here:
http://www.opengroup.org/onlinepubs/009695399/functions/exec.html
Namely:
The new process shall inherit at least the following attributes from the calling process image:
... Process signal mask (see sigprocmask())
Shcheklein
2010-08-13 22:21:50
+2
A:
nohup simply exec
's the command you give it after ignoring the HUP
signal. From the source code:
signal (SIGHUP, SIG_IGN);
/* skipping some stuff ... */
execvp (*cmd, cmd);
I'm assuming this means that if the specified command did something like:
signal (SIGHUP, SIG_DFL); /* restore default HUP signal handler */
nohup wouldn't work properly.
cam
2010-08-13 22:34:30