help needed with froked process becoming zombies

Carlos O'Donell carlos@systemhalted.org
Mon Aug 27 13:32:00 GMT 2012


On Mon, Aug 27, 2012 at 9:25 AM, Godmar Back <godmar@gmail.com> wrote:
> 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

That's the behaviour I would expect, so it seems there is no kernel
bug in 3.2.0 atleast.

Cheers,
Carlos.



More information about the Libc-help mailing list