#include #include #include #include #include void MoveToChild(int n) { pid_t pid; if ( (pid = fork()) == -1 ) { perror("fork()"); _exit(1); } else if ( pid != 0 ) { printf("Parent %d [%d] exit.\n", n, getpid()); _exit(0); } printf("Child %d [%d] works.\n", n, getpid()); } void *thread_main(void *args) { int i; for (i=0; i<5; i++) MoveToChild(i); return NULL; } int main() { pthread_t t; pthread_create(&t, NULL, thread_main, NULL); pthread_join(t, NULL); return 0; }