Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 29 Mar 2002 17:18:06 -0800 (PST)
From:      Gurusamy Sarathy <gsar@ActiveState.com>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/36515: SA_NOCLDWAIT has no effect when linking with -pthread
Message-ID:  <200203300118.g2U1I6W82724@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         36515
>Category:       kern
>Synopsis:       SA_NOCLDWAIT has no effect when linking with -pthread
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Mar 29 17:20:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Gurusamy Sarathy
>Release:        4.2-RELEASE
>Organization:
ActiveState Corp.
>Environment:
FreeBSD clamp 4.2-RELEASE FreeBSD 4.2-RELEASE #0: Mon Nov 20 13:02:55 GMT 2000     jkh@bento.FreeBSD.org:/usr/src/sys/compile/GENERIC  i386      
>Description:
Merely linking a program with -pthread causes it to start producing
zombies, even though the program has explicitly set the SIGCHLD disposition using SA_NOCLDWAIT. Problem does not appear when not
linking with -pthread.  The supplied test case should be self-
explanatory.

>How-To-Repeat:
/*
 * Demonstrate that SA_NOCLDWAIT doesn't work when linking with -pthread
 * under FreeBSD 4.2-RELEASE.
 *
 * This program has different behavior when built with and without
 * -pthread.  When built with -pthread, it will create zombies.
 *
 * The two variants can be built with:
 *
 *    cc -o sig sig.c
 *    cc -o sig sig.c -pthread
 */

#include <stdio.h>
#include <signal.h>
#include <errno.h>

int
main(int ac, char **av)
{
    struct sigaction sa;

    sa.sa_handler = SIG_IGN;
    sa.sa_flags = SA_NOCLDWAIT;
    sigemptyset(&sa.sa_mask);
    sigaction(SIGCHLD,&sa,NULL);
    while (1) {
        int c = fork();
        if (c < 0) {
            fprintf(stderr, "fork() failed: %s\n", strerror(errno));
            exit(1);
        }
        if (!c) {
            exit(0);
        }
        sleep(1);
    }
}
     
>Fix:
Don't know of a fix, but the workaround is to install an explicit
handler to reap the children.      
>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200203300118.g2U1I6W82724>