tags:

views:

40

answers:

3

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?

+1  A: 

May the source be with you :)

Disclamer: the phrase is actually not mine, but of Marshall Kirk McKusick.

Nikolai N Fetissov
+1. That's essentially 2 lines of code if you remove all the additional processing. :)
casablanca
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
+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
jilles
Ah, that seems like a sensible convention. I couldn't imagine why anyone would want to reset HUP to default, but I thought I would point that out.
cam