2011-06-07 12:13:24 +02:00
/* Test handle_group_exit() handling of a thread leader still alive with its
* thread child calling exit_group ( ) and proper passing of the process exit
2007-07-05 18:43:18 +00:00
* code to the process parent of this whole thread group .
2009-07-08 11:21:17 +00:00
*
2007-07-05 18:43:18 +00:00
* gcc - o test / leaderkill test / leaderkill . c - Wall - ggdb2 - pthread ; . / test / leaderkill & pid = $ ! ; sleep 1 ; strace - o x - q . / strace - f - p $ pid
* It must print : write ( 1 , " OK \n " , . . .
*/
# include <pthread.h>
# include <assert.h>
# include <unistd.h>
# include <stdlib.h>
# include <stdio.h>
# include <sys/wait.h>
2009-02-25 14:24:02 +00:00
static void * start0 ( void * arg )
2007-07-05 18:43:18 +00:00
{
2009-02-25 14:24:02 +00:00
sleep ( 1 ) ;
exit ( 42 ) ;
2007-07-05 18:43:18 +00:00
}
2009-02-25 14:24:02 +00:00
static void * start1 ( void * arg )
2007-08-03 10:02:02 +00:00
{
2009-02-25 14:24:02 +00:00
pause ( ) ;
/* NOTREACHED */
assert ( 0 ) ;
2007-08-03 10:02:02 +00:00
}
2009-02-25 14:24:02 +00:00
int main ( int argc , char * argv [ ] )
2007-07-05 18:43:18 +00:00
{
2009-02-25 14:24:02 +00:00
pthread_t thread0 ;
pthread_t thread1 ;
pid_t child , got_pid ;
int status ;
int i ;
sleep ( 2 ) ;
child = fork ( ) ;
2007-07-05 18:43:18 +00:00
2011-06-07 12:13:24 +02:00
switch ( child ) {
2009-02-25 14:24:02 +00:00
case - 1 :
abort ( ) ;
case 0 :
i = pthread_create ( & thread0 , NULL , start0 , NULL ) ;
assert ( i = = 0 ) ;
i = pthread_create ( & thread1 , NULL , start1 , NULL ) ;
assert ( i = = 0 ) ;
pause ( ) ;
/* NOTREACHED */
assert ( 0 ) ;
break ;
default :
got_pid = waitpid ( child , & status , 0 ) ;
assert ( got_pid = = child ) ;
assert ( WIFEXITED ( status ) ) ;
assert ( WEXITSTATUS ( status ) = = 42 ) ;
puts ( " OK " ) ;
exit ( 0 ) ;
}
2007-07-05 18:43:18 +00:00
/* NOTREACHED */
2009-02-25 14:24:02 +00:00
abort ( ) ;
2007-07-05 18:43:18 +00:00
}