blob: de5228c5caa15c0f76047e153da5a89a39bc6bc3 [file] [log] [blame]
njn1d3566c2005-03-13 05:10:08 +00001#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
9static void *threadmain( void *dummy )
10{
sewardj90527e32006-10-17 11:09:03 +000011 sleep( (unsigned long)dummy );
njn1d3566c2005-03-13 05:10:08 +000012 return NULL;
13}
14
15int main( int argc, char **argv )
16{
sewardj4bdd5052006-10-17 01:28:48 +000017 int ctr;
njn1d3566c2005-03-13 05:10:08 +000018 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 );
sewardj4bdd5052006-10-17 01:28:48 +000040 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 }
njn1d3566c2005-03-13 05:10:08 +000049
50 printf("PASS\n");
51
52 return 0;
53}
54
55