From owner-freebsd-bugs Tue Nov 16 5:30: 6 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 7536614CBE for ; Tue, 16 Nov 1999 05:30:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id FAA20808; Tue, 16 Nov 1999 05:30:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Tue, 16 Nov 1999 05:30:02 -0800 (PST) Message-Id: <199911161330.FAA20808@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Jonathan M. Bresler" Subject: i386/14689: waitpid doesn't harvest child process when Reply-To: "Jonathan M. Bresler" Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR i386/14689; it has been noted by GNATS. From: "Jonathan M. Bresler" 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 #include #include #include #include #include #include #include #include #include #include #include #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