4

I have a main process that has forked some kid processes.

Each kid does something and blocks itself. By blocking itself every child sends a SICHLD signal to the parent process.

I also have declared a sigaction action, in the main process code, in order to catch the SIGCLHD that the kids will send.

static struct sigaction action;
action.sa_handler = handler 
sigfillset(&(action.sa_mask));
sigaction(SIGCHLD, &action, NULL);

The SIGCHLD handler when called, checks which kid sent the SIGCHLD signal and does something for that kid.

The question is, what happens if multiple kids send signals at the same time? Let's say that kid(1) sent SIGCHLD. The handler catches it and before he completes the handle, kid(2) and kid(3) both send signals. Will the handler run for each of these signals after he is done with kid(1) or will these signals get ignored?

Grijesh Chauhan
  • 57,103
  • 20
  • 141
  • 208
pirox22
  • 892
  • 1
  • 14
  • 30

1 Answers1

0

SIGCHLD is somewhat special in that you get exactly one signal per exiting child; these signals are tied to the corresponding zombies/wait-status left behind by the child processes they correspond to. But in general most signals are just flags, not queues. If possible it's best not to use SIGCHLD and instead just use waitpid and track child exit in some other way (e.g. by observing EOF status on a pipe from the child in your poll loop or such).

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • The kid process does not exit when it does it's job, it just changes state to "stopped". I am already using waitpid in order to see which kid changed state to "stopped". – pirox22 Apr 10 '15 at 07:56
  • Hmm, I'm not sure of the exact rules for stopping but I think they're the same, except possibly in the case where the stopped process resumes before the signal is able to be delivered... – R.. GitHub STOP HELPING ICE Apr 10 '15 at 08:12