#include #include #include void prepare(void) { printf("preparing from %d\n", getpid()); } void parent(void) { printf("parent from %d\n", getpid()); } void child(void) { printf("child from %d\n", getpid()); } int main(void) { pid_t pid; pthread_atfork(prepare, parent, child); if ((pid = fork())) { printf("I'm the parent %d with child %d\n", getpid(), pid); } else { printf("I'm the child %d\n", getpid()); } return 0; }