njn | 1d3566c | 2005-03-13 05:10:08 +0000 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <sys/wait.h> |
| 3 | #include <pthread.h> |
| 4 | #include <sys/types.h> |
| 5 | #include <unistd.h> |
| 6 | #include <stdio.h> |
| 7 | #include <signal.h> |
| 8 | |
| 9 | static void *threadmain( void *dummy ) |
| 10 | { |
sewardj | 90527e3 | 2006-10-17 11:09:03 +0000 | [diff] [blame] | 11 | sleep( (unsigned long)dummy ); |
njn | 1d3566c | 2005-03-13 05:10:08 +0000 | [diff] [blame] | 12 | return NULL; |
| 13 | } |
| 14 | |
| 15 | int main( int argc, char **argv ) |
| 16 | { |
sewardj | 4bdd505 | 2006-10-17 01:28:48 +0000 | [diff] [blame] | 17 | int ctr; |
njn | 1d3566c | 2005-03-13 05:10:08 +0000 | [diff] [blame] | 18 | pid_t childpid; |
| 19 | pthread_t childthread; |
| 20 | void *res; |
| 21 | int status; |
| 22 | |
| 23 | pthread_create( &childthread, NULL, threadmain, (void *)2 ); |
| 24 | |
| 25 | childpid = fork(); |
| 26 | switch( childpid ) { |
| 27 | case 0: |
| 28 | pthread_create( &childthread, NULL, threadmain, 0 ); |
| 29 | pthread_join( childthread, &res ); |
| 30 | exit(0); |
| 31 | break; |
| 32 | case -1: |
| 33 | perror( "FAILED: fork failed\n" ); |
| 34 | break; |
| 35 | default: |
| 36 | break; |
| 37 | } |
| 38 | |
| 39 | pthread_join( childthread, &res ); |
sewardj | 4bdd505 | 2006-10-17 01:28:48 +0000 | [diff] [blame] | 40 | ctr = 0; |
| 41 | while(waitpid(childpid, &status, 0) != childpid) { |
| 42 | sleep(1); |
| 43 | ctr++; |
| 44 | if (ctr >= 10) { |
| 45 | printf("FAILED - timeout waiting for child\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | } |
njn | 1d3566c | 2005-03-13 05:10:08 +0000 | [diff] [blame] | 49 | |
| 50 | printf("PASS\n"); |
| 51 | |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | |