Date: Tue, 16 Nov 1999 05:30:02 -0800 (PST) From: "Jonathan M. Bresler" <jmb@hub.freebsd.org> To: freebsd-bugs@FreeBSD.org Subject: i386/14689: waitpid doesn't harvest child process when Message-ID: <199911161330.FAA20808@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR i386/14689; it has been noted by GNATS. From: "Jonathan M. Bresler" <jmb@hub.freebsd.org> To: freebsd-gnats-submit@freebsd.org Cc: wpk@isc.org Subject: i386/14689: waitpid doesn't harvest child process when Date: Tue, 16 Nov 1999 05:23:58 -0800 (PST) program run under cron Bill, Thanks for the code snippet. I am going to add the code and the results of running it to the bug tracking system. jmb ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ run from an xterm: baby:[215] ./x child 26962, deadpid 26962, errno 0, T_int 0 deadpid == child ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ run from cron child 26951, deadpid -1, errno 4, T_int 14 terminating child child 26951, deadpid 26951, errno 3, T_int 0 deadpid == child ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Example Code: #include <ctype.h> #include <errno.h> #include <limits.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <signal.h> #include <time.h> #include <unistd.h> #include <pthread.h> #define T_TIMEOUT 60 static int T_timeout; static int T_int; static void t_sighandler(); static void t_sighandler(int sig) { T_int = sig; } int main(int argc, char **argv) { pid_t child; pid_t deadpid; int status; struct sigaction sa; T_timeout = T_TIMEOUT; /* setup signals */ sa.sa_flags = 0; sigfillset(&sa.sa_mask); sa.sa_handler = t_sighandler; (void) sigaction(SIGALRM, &sa, NULL); (void) sigaction(SIGINT, &sa, NULL); setbuf(stdout, NULL); child = fork(); if (child == 0) { sleep(10); exit(0); } else if (child > 0) { T_int = 0; sa.sa_handler = t_sighandler; (void) sigaction(SIGALRM, &sa, NULL); alarm(T_timeout); deadpid = (pid_t) -1; while (deadpid != child) { deadpid = waitpid(child, &status, 0); printf("child %d, deadpid %d, errno %d, T_int %d\n", child, deadpid, errno, T_int); if (deadpid == child) { printf("deadpid == child\n"); if (WIFSIGNALED(status)) { if (WTERMSIG(status) == SIGTERM) printf("the test case timed out\n"); else printf("the test case caused exception %d\n", WTERMSIG(status)); } } else if ((deadpid == -1) && (errno == EINTR) && T_int) { printf("terminating child\n"); kill(child, SIGTERM); T_int = 0; } else if ((deadpid == -1) && ((errno == ECHILD) || (errno == ESRCH))) { printf("no such process\n"); break; } } sa.sa_handler = SIG_IGN; (void) sigaction(SIGALRM, &sa, NULL); alarm(0); } else { printf("fork failed, errno == %d\n", errno); } return(0); } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199911161330.FAA20808>