Subject: fatal race condition
From: [email-masked] (Tim Newsham)

21 Jul 1997 16:43:39 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Original-To: [email-masked]
X-Mailer: ELM [version 2.4 PL24 PGP3 *ALPHA*]
Original-Sender: [email-masked]

Hi,,

   There's a race condition between fork and signals.  This program
demonstrates the problem.

                                          Tim N.

--- forkbug.c ---

/*
 * forkbug.c
 *	Demonstrate bug in cygwin fork and signal code
 *
 * This code demonstrates a race condition between the signal code
 * and the fork code in cygwin.  When run this program will lock
 * up all cygwin processes.  The problem occurs when a signal
 * is delivered to a process when it is forking.  This seems
 * to corrupt the process' state which later causes the system
 * to hang when the process exits.
 */

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

int child;

void
handler(int sig)
{
    /* send signal to child, child should be in fork() */
    kill(child, SIGINT);
}

main()
{
    int res;

    child = fork();
    if(child == 0) {
        /* child -
         * sleep, then signal parent, then fork
         * parent will signal us while we're forking
         */
        sleep(1);
        kill(getppid(), SIGINT);
        res = fork();
        printf("done fork, child %d, pid %d, parent %d\n", 
            res, getpid(), getppid());
        exit(0);
    } else {
        /* parent -
         * sleep waiting for signal
         */
        signal(SIGINT, handler);
        sleep(20);
        exit(0);
    }
}
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".