/* * glibc 2.3.2 signal race example * * Simon Kirby , 2003/08/21 * * Compile with the following: * * gcc -o signal-crash-example signal-crash-example.c -lpthread * * This should cause a Segmentation fault shortly in a second or so when * used on glibc 2.3.2 (2.3.1 and before are unaffected). NTPL-enabled * kernels (eg: Red Hat 9.0 kernels) are also unaffected. This program * must be compiled with libpthread to show the problem. */ #include #include #include #include #include #include void signalhandler(int sig) { } int main(int argc, char *argv[]) { pid_t pid; int i; while (1) { for (i = 0; i < 100; i++){ if ((pid = fork()) == -1) { perror("Fork error"); exit(1); } if (pid == 0) { usleep(100000); signal(SIGCHLD, SIG_DFL); exit(0); } } usleep(100000); for (i = 0; i < 10000; i++){ signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, signalhandler); signal(SIGCHLD, SIG_DFL); signal(SIGCHLD, signalhandler); } while (wait(NULL) != -1) ; } }