This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: help needed with froked process becoming zombies
On Mon, Aug 27, 2012 at 9:18 AM, Carlos O'Donell
<carlos@systemhalted.org> wrote:
>
> On Sun, Aug 26, 2012 at 11:58 PM, Siddhesh Poyarekar
> <siddhesh.poyarekar@gmail.com> wrote:
> > On 27 August 2012 06:48, Christoph Anton Mitterer <calestyo@scientia.net> wrote:
> >>> The alternative is to ignore
> >>> SIGCHLD in the parent and then the kernel knows it should not keep the
> >>> child around and should reap the child on exit (not leaving a zombie).
> >> I tried that,... added a:
> >> signal(SIGCHILD, SIG_IGN);
> >> to the default: case of the switch... no change.
> >
> > I don't think you can do that. For the kernel to not signal the
> > parent, the signal needs to be removed from the underlying clone
> > system call and that can only be done if you're calling clone
> > directly, not via fork.
>
> I'd argue that's a kernel bug.
>
Is that really true? Auto-reaping not working for fork()? My
experiment shows it works on my machine:
$ cat autoreap.c
#include <signal.h>
#include <unistd.h>
int
main(int ac, char av[])
{
if (ac > 1)
signal(SIGCHLD, SIG_IGN);
if (fork()) {
sleep(1);
system("ps f");
}
}
--
output (no autoreap)
$ ./autoreap
....
14325 pts/18 S+ 0:00 \_ ./autoreap
14326 pts/18 Z+ 0:00 \_ [autoreap] <defunct>
14327 pts/18 S+ 0:00 \_ sh -c ps f
14328 pts/18 R+ 0:00 \_ ps f
output (with autoreap)
$ ./autoreap auto
...
14329 pts/18 S+ 0:00 \_ ./autoreap auto
14331 pts/18 S+ 0:00 \_ sh -c ps f
14332 pts/18 R+ 0:00 \_ ps f
On Ubuntu 12.04, libc 2.15, kernel 3.2.0
- Godmar