开发者

Is it possible to change the signal handlers in another process?

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?


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.


May the source be with you :)

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


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())

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜