This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

fork handler for parent process called in both parent and child process


Please consider the following testcase:

####################
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>   // compile with -lpthread or -pthread

void atfork_prepare()
{
    printf("atfork_prepare, pid: %d\n", getpid());
}

void atfork_parent()
{
    printf("atfork_parent, pid: %d\n", getpid());
}

void atfork_child()
{
    printf("atfork_child, pid: %d\n", getpid());
}

void main()
{
    pthread_atfork(atfork_prepare, atfork_parent, atfork_child);
    pid_t pid = fork();
    if (pid == 0) {   // child
        exit(0);
    }
    printf("pid of parent process: %d\n", getpid());
    printf("pid of child process: %d\n", pid);
    waitpid(pid, NULL, 0);
    exit(0);
}
####################

On Cygwin, I get:

$ ./testcase
atfork_prepare, pid: 11560
atfork_child, pid: 7744
atfork_parent, pid: 7744
atfork_parent, pid: 11560
pid of parent process: 11560
pid of child process: 7744

atfork_parent() is called in both the parent and the child process, but
as far as I understand, it should be called in the parent process only.

Best regards,
Andreas


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]