Back to index

glibc  2.9
ex15.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 #include <sys/wait.h>
00005 #include <pthread.h>
00006 #include <unistd.h>
00007 
00008 static void *worker (void *dummy) __attribute__ ((__noreturn__));
00009 
00010 static void *
00011 worker (void *dummy)
00012 {
00013   exit (26);
00014 }
00015 
00016 #define TEST_FUNCTION do_test ()
00017 #define TIMEOUT 10
00018 static int
00019 do_test (void)
00020 {
00021   pthread_t th;
00022   pid_t pid;
00023   int status;
00024 
00025   switch ((pid = fork ()))
00026     {
00027     case -1:
00028       puts ("Could not fork");
00029       exit (1);
00030     case 0:
00031       if (pthread_create(&th, NULL, worker, NULL) != 0)
00032        {
00033          puts ("Failed to start thread");
00034          exit (1);
00035        }
00036       for (;;);
00037       exit (1);
00038     default:
00039       break;
00040     }
00041 
00042   if (waitpid (pid, &status, 0) != pid)
00043     {
00044       puts ("waitpid failed");
00045       exit (1);
00046     }
00047 
00048   if (!WIFEXITED (status) || WEXITSTATUS (status) != 26)
00049     {
00050       printf ("Wrong exit code %d\n", status);
00051       exit (1);
00052     }
00053 
00054   puts ("All OK");
00055   return 0;
00056 }
00057 
00058 #include "../../test-skeleton.c"