#include #include #include #include #include #include static void *tick_thread(void *unused) { while (1) { pthread_testcancel(); printf("tick\n"); sleep(1); } return NULL; } int main(int argc, char **argv) { pid_t pid; pthread_t tid; void *ret; if (pthread_create(&tid, NULL, tick_thread, NULL) < 0) { printf("pthread_create failed\n"); return 1; } pid = vfork(); if (pid == 0) { printf("sleeping\n"); sleep(10); printf("done sleeping\n"); execl("/bin/echo", "echo", "hello world", NULL); exit(1); } else if (pid > 0) { printf("vfork() returned\n"); waitpid(pid, NULL, 0); } else { printf("vfork failed\n"); return 1; } pthread_cancel(tid); pthread_join(tid, &ret); return 0; }