1

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:

(void) sigset(SIGINT, intHandler);
BenMorel
  • 34,448
  • 50
  • 182
  • 322
zetatr
  • 179
  • 1
  • 3
  • 8
  • "except for the sender process" -- the spec doesn't say that. You need to block SIGTERM, or remove your process from the process group. – Jim Balter May 10 '11 at 02:47
  • or keep track of the child in a global and explicitly `kill` the child instead of all processes. IIRC, you can also use `sigaction` to ensure that `SIGTERM` is ignored by the parent and unblocked in the child. – D.Shawley May 10 '11 at 02:55
  • I ended up doing exactly what you said and it works exactly as I need it to.Thanks – zetatr May 10 '11 at 03:11

1 Answers1

4

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.