gareth> Hi,
gareth> Here is the code I use to handle signal SIGCHLD. Can anyone
gareth> tell me why there's still some zombie processes? I wonder the
gareth> problem is caused by another SIGCHLD signal occurs when the
gareth> program is inside the signal handler. How to prevent this or
gareth> why there's zombie processes?(on FreeBSD3.3R)
Firstly, always use sigaction() to install signal handlers, not signal().
Secondly, you need to loop in the signal handler:
void chldhdlr(int signo)
{
int status;
pid_t pid;
int saveerrno = errno;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
/* do whatever you want to do with PID and STATUS */;
errno = saveerrno;
Quote:}
If you still see zombie processes that persist, then make sure you're
not blocking SIGCHLD inappropriately. (If you do anything in your
signal handler that accesses global data, then you need to block
SIGCHLD when you access that data in your main code, but make sure
that you're unblocking it correctly.)
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>