[Qeustion][Maybe BUG?] simaltaneous wait and SIGCHLD handling

From: KAMEZAWA Hiroyuki
Date: Mon Feb 19 2007 - 01:14:36 EST


>From SUSv3, I expected SIGCHLD from dead processes (already reaped by wait(2))
should be cleared. But it seems that such situation is not handled in Linux.

Here is a test program. set sigchld handler and call waitpid() in main().

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>

int sigchld_handler(int sig,siginfo_t *info, void *uc)
fprintf(stderr,"Letter from the hell...(%d)\n",info->si_pid);

int main(int argc, char *argv)
struct sigaction act;
sigset_t block;
int status;
pid_t pid;

sigaddset(&block, SIGCHLD);
act.sa_sigaction = sigchld_handler;
act.sa_mask = block;
act.sa_flags = SA_SIGINFO|SA_RESTART;

pid = fork();
if (!pid) {
sigprocmask(SIG_BLOCK, &block, NULL);
pid = waitpid(pid, &status, 0);
fprintf(stderr,"wait end -> %d\n",pid);
sigprocmask(SIG_UNBLOCK, &block, NULL);
Result is here
[kamezawa@casares ~]$ ./waittest
wait end -> 5841
Letter from the hell...(5841)

Is this an expected result ? I think SIGCHLD shouldn't be delivered.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/