1 /* $OpenBSD: main-thread-exited.c,v 1.2 2014/05/20 01:25:24 guenther Exp $ */ 2 /* PUBLIC DOMAIN Mar 2012 <guenther@openbsd.org> */ 3 4 5 #include <sys/types.h> 6 #include <sys/wait.h> 7 #include <err.h> 8 #include <errno.h> 9 #include <pthread.h> 10 #include <signal.h> 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 #include <unistd.h> 15 16 void * 17 tmain(void *arg) 18 { 19 sleep(1); 20 printf("sending SIGKILL\n"); 21 kill(getpid(), SIGKILL); 22 sleep(1); 23 printf("still running!\n"); 24 exit(1); 25 } 26 27 int 28 main(int argc, char **argv) 29 { 30 pid_t pid; 31 pthread_t t; 32 int r; 33 34 pid = fork(); 35 if (pid == -1) 36 err(1, "fork"); 37 if (pid > 0) { 38 int status; 39 40 if (waitpid(pid, &status, 0) != pid) 41 err(1, "waitpid"); 42 exit(! WIFSIGNALED(status) || WTERMSIG(status) != SIGKILL); 43 } 44 45 /* in child */ 46 if ((r = pthread_create(&t, NULL, tmain, NULL))) 47 errc(1, r, "pthread_create"); 48 pthread_exit(NULL); 49 abort(); 50 } 51