signals dropped when proc. run as daemon, but not when in the foreground

From: John Z. Bohach
Date: Tue Sep 25 2007 - 23:44:32 EST


I'm writing a system app. that becomes a daemon by the usual fork() ->
setsid() -> fork() method.

It then registers a signal handler for SIGCHLD via sigaction (SA_SIGINFO

chldAction.sa_sigaction = sigChld;
chldAction.sa_flags = SA_SIGINFO;
rc = sigaction(SIGCHLD, &chldAction, NULL);

Its a network service server, so it does the usual
socket->bind->listen->select->accept->fork sequence to handle a new

The child processes the connection, then exits. This should generate
the standard SIGCHLD signal to the parent, which catches it via the
sigaction with the following handler:

static void
sigChld(int signum, siginfo_t * siginfo, void * ucontext)
int childStat;

log_dbg("received signal %d\n", signum);

if (signum != SIGCHLD) /* technically can't happen here... */
return; /* but ignore it if it does */

if (waitpid(siginfo->si_pid, &childStat, 0) > 0)
if (WIFEXITED(childStat))
log_dbg("child %d WIFEXITED with childStat %d\n",
siginfo->si_pid, WEXITSTATUS(childStat));

if (WIFSIGNALED(childStat))
log_dbg("child %d WIFSIGNALED with childStat %d\n",
siginfo->si_pid, WTERMSIG(childStat));


Here's the problem: when run as a daemon, as above, I don't get the
SIGCHLD. I've instrumented it to show the child exiting, and it does,
and it even becomes defunct (on account of the lack of waitpid from the
signal handler).

HOWEVER, if I run the program in the foreground, without
fork()->setsid()->fork() sequence, EVERYTHING is FINE!

I am going insane? This is on a kernel, and I just can't see
that this would be a kernel bug, but I don't know if/what I'm doing
wrong myself?

Is there something I could do to test something...I've been at this for
a few days now and I'm out of ideas...


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at