Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 1 | /* Test handle_group_exit () handling of a thread leader still alive with its |
| 2 | * thread child calling exit_group () and proper passing of the process exit |
| 3 | * code to the process parent of this whole thread group. |
Denys Vlasenko | b1efe53 | 2008-12-23 16:14:42 +0000 | [diff] [blame^] | 4 | * |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 5 | * gcc -o test/leaderkill test/leaderkill.c -Wall -ggdb2 -pthread;./test/leaderkill & pid=$!;sleep 1;strace -o x -q ./strace -f -p $pid |
| 6 | * It must print: write(1, "OK\n", ... |
| 7 | */ |
| 8 | |
| 9 | #include <pthread.h> |
| 10 | #include <assert.h> |
| 11 | #include <unistd.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> |
| 14 | #include <sys/wait.h> |
| 15 | |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 16 | static void *start0 (void *arg) |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 17 | { |
| 18 | sleep (1); |
| 19 | |
| 20 | exit (42); |
| 21 | } |
| 22 | |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 23 | static void *start1 (void *arg) |
| 24 | { |
| 25 | pause (); |
| 26 | /* NOTREACHED */ |
| 27 | assert (0); |
| 28 | } |
| 29 | |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 30 | int main (void) |
| 31 | { |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 32 | pthread_t thread0; |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 33 | pthread_t thread1; |
| 34 | int i; |
| 35 | pid_t child, got_pid; |
| 36 | int status; |
| 37 | |
| 38 | sleep (2); |
| 39 | |
| 40 | child = fork (); |
| 41 | switch (child) |
| 42 | { |
| 43 | case -1: |
| 44 | abort (); |
| 45 | case 0: |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 46 | i = pthread_create (&thread0, NULL, start0, NULL); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 47 | assert (i == 0); |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 48 | i = pthread_create (&thread1, NULL, start1, NULL); |
| 49 | assert (i == 0); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 50 | pause (); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 51 | /* NOTREACHED */ |
Roland McGrath | a2eed4f | 2007-08-03 10:02:02 +0000 | [diff] [blame] | 52 | assert (0); |
Roland McGrath | e1e57b2 | 2007-07-05 18:43:18 +0000 | [diff] [blame] | 53 | break; |
| 54 | default: |
| 55 | got_pid = waitpid (child, &status, 0); |
| 56 | assert (got_pid == child); |
| 57 | assert (WIFEXITED (status)); |
| 58 | assert (WEXITSTATUS (status) == 42); |
| 59 | puts ("OK"); |
| 60 | exit (0); |
| 61 | } |
| 62 | /* NOTREACHED */ |
| 63 | abort (); |
| 64 | } |