Catching termination of child process and system() call
Vasile R. Montan
vrm at babcock.cerc.wvu.wvnet.edu
Fri Jan 25 06:13:51 AEST 1991
>From article <1991Jan24.084230.12153 at cai.uucp>, by davel at cai.uucp (David W. Lauderback):
> However, if you are just trying to get rid of left-over child processes
> "zombie processes",
> just use:
> signal(SIGCHLD,SIG_IGN);
> instead of:
> signal(SIGCHLD, dowait);
> and you need no wait. (see signal(2) or signal(3c) in BSD)
>
> FYI: The zombie process is storing the child process' exit status, so must
> remain until its parent process has read this information. SIG_IGN to SIGCHLD
> states this process' child's return value should be discarded.
I have seen this solution proposed many times, but it doesn't work
for me. I am using a Sun4 SunOS4.1. I have created the following test
routine. Maybe someone could tell me if I am doing something wrong or
if it is the operating system.
#include <signal.h>
main()
{
int i;
signal(SIGCHLD, SIG_IGN);
for (i=0; i< 10; i++) {
if (! fork()) exit (0);
}
while (1) {}
}
It generates 10 children, which immediately exit then it waits in an
infinite loop. When I do a "ps", I see all 10 <defunct> processes
hanging around.
More information about the Comp.lang.c
mailing list