开发者

signal handler function keeps looping

My function created to handle the SIGINT signal is stuck in a constant loop. The idea is to make CTRL-C ignored by the parent process but sent to the child process (and they handle it as default). What happens is when I press CTRL-C, the signal handler function is called but gets stuck in an endless loop. The kill call is supposed to send SIGTERM to all process in the process group except for the sender process. Any help would be appreciated.

the function code is:

void intHandler(int signum) {
kill(0, SIGTERM);

}

the function call code (in main) is:

开发者_如何学JAVA(void) sigset(SIGINT, intHandler);


From the kill man page.

If pid is 0, sig shall be sent to all processes (excluding an unspecified set of system processes) whose process group ID is equal to the process group ID of the sender, and for which the process has permission to send a signal.

Nothing about not sending the signal to the sender, so you most likely want something like:

void intHandler(int signum) {
    sigset(SIGINT, SIG_DFL);
    kill(0, SIGTERM);
}

This will reset your signal handler in the sender to default before sending the SIGTERM to all members of the process group.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜