1 #include <pthread.h> 2 #include <signal.h> 3 #include <stdlib.h> 4 #include <stdio.h> 5 #include <string.h> 6 #include <unistd.h> 7 #include <sys/wait.h> 8 9 void *slavethread(void *arg) 10 { 11 while (1) 12 pause(); 13 } 14 15 int main(int argc, char **argv) 16 { 17 int i; 18 for (i = 0; i < 10; i++) { 19 pthread_t slave; 20 if (pthread_create(&slave, 0, slavethread, 0)) { 21 perror("pthread_create"); 22 exit(2); 23 } 24 } 25 26 pid_t pid = getpid(); 27 switch (fork()) { 28 case 0: // child 29 sleep(2); // Should be enough to ensure (some) threads are created 30 for (i = 0; i < 20 && kill(pid, SIGTERM) == 0; i++) 31 ; 32 exit(0); 33 case -1: 34 perror("fork"); 35 exit(4); 36 } 37 38 while (1) 39 pause(); 40 fprintf(stderr, "strange, this program is supposed to be killed!\n"); 41 return 1; 42 } 43