#include #include #include #include void *thread_func_2(void* args) { puts("thread_func_2"); /* hang up here */ } void *thread_func_1(void* args) { int ret; pid_t pid; puts("thread_func_1"); pid = fork(); assert(pid != (pid_t)-1); if (pid != 0) /* parent process */ { int status; printf("parent process (child pid = %d)\n", pid); waitpid(pid, &status, 0); puts("parent process end"); } else /* child process */ { pthread_t thread; puts("child process"); ret = pthread_create(&thread, NULL, thread_func_2, NULL); assert(ret == 0); ret = pthread_join(thread, NULL); assert(ret == 0); puts("child process end"); } return args; } int main() { int ret; pthread_t thread; ret = pthread_create(&thread, NULL, thread_func_1, NULL); assert(ret == 0); ret = pthread_join(thread, NULL); assert(ret == 0); }