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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

>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;

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

        pid = fork();
        if (!pid) {
                sleep(3);
                exit(0);
        }
        sigprocmask(SIG_BLOCK, &block, NULL);
        pid = waitpid(pid, &status, 0);
        fprintf(stderr,"wait end -> %d\n",pid);
        sigprocmask(SIG_UNBLOCK, &block, NULL);
        exit(0);
}
==
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.

-Kame

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

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux