From: UnixOS2 Archive To: "UnixOS2 Archive" Date: Mon, 15 Sep 2003 14:11:37 EST-10EDT,10,-1,0,7200,3,-1,0,7200,3600 Subject: [UnixOS2_Archive] No. 194 ************************************************** Sunday 14 September 2003 Number 194 ************************************************** Subjects for today 1 waitpid : why does this not work? : Thomas Hoffmann **= Email 1 ==========================** Date: Mon, 15 Sep 2003 21:50:26 +0200 From: Thomas Hoffmann Subject: waitpid : why does this not work? I did not find too many discussion about waitpid() on older OS/2+emx archives, so I will ask this here: According to some sample code e.g. in the glibc documentation something like this should collect all the children of a process in a signal handler for SIGCLD/SIGCHLD: static RETSIGTYPE chldHndl(int foo) { pid_t pid; int status; int save_errno = errno; sigset_t sigs; static int dct=0; sigfillset(&sigs); /* Block signals so that NotifyDeadProcess() doesn't get fux0red */ sigprocmask(SIG_BLOCK, &sigs, NULL); /* If 2 or more kids exit in a small time window, before this handler gets * the chance to get invoked, the SIGCHLD signals will be merged and only * one SIGCHLD signal will be sent to us. We use a while loop to get all * exited child status because we can't count on the number of SIGCHLD * signals to know exactly how many kids have exited. -Dan */ while ((pid=waitpid(-1, &status, WNOHANG))>0 || (pid<0 && errno==EINTR)) { printf("bury dbg 4a: %i - %i -%i\n"),dct++,pid,status); NotifyDeadProcess(pid, WEXITSTATUS(status)); printf("bury dbg 4b: %i - %i -%i\n"),dct++,pid,status); } WDelayedActionSet++; sigprocmask(SIG_UNBLOCK, &sigs, NULL); errno = save_errno; } But it does not work at all for me: an infinite loop starts as soon as this handler is entered. The log file reads (messages starting w/ "warning" come from NotifyDeadprocess()): bury dbg 4a: 0 - 153 -0 warning: debug stack:dead process (pid=153) bury dbg 4b: 1 - 153 -0 bury dbg 4a: 2 - 153 -0 warning: debug stack:dead process duplicate id (pid=153) bury dbg 4b: 3 - 153 -0 bury dbg 4a: 4 - 153 -0 warning: debug stack:dead process duplicate id (pid=153) bury dbg 4b: 5 - 153 -0 bury dbg 4a: 6 - 153 -0 warning: debug stack:dead process duplicate id (pid=153) bury dbg 4b: 7 - 153 -0 bury dbg 4a: 8 - 153 -0 warning: debug stack:dead process duplicate id (pid=153) bury dbg 4b: 9 - 153 -0 bury dbg 4a: 10 - 153 -0 warning: debug stack:dead process duplicate id (pid=153) bury dbg 4b: 11 - 153 -0 ..... I can not make any sense of this return with a valid pid and a status of 0: can anybody of you? Thomas. -- Thomas Hoffmann thoffman at zappa.sax.de Dresden, Germany ..sig under construction ...