in reply to daemon/fork: defunct parent not going away nicely

It'll be defunct because crond hasn't yet reaped the exited process. As to why it hasn't, I don't know; but I would speculate that crond is waiting for one for more of the STDIN/STDOUT/STDRR it passed to it's child to reach EOF; and maybe your child (crond's grandchild) is inheriting those file descriptors?

Dave.

  • Comment on Re: daemon/fork: defunct parent not going away nicely

Replies are listed 'Best First'.
Re^2: daemon/fork: defunct parent not going away nicely
by Eliya (Vicar) on Oct 14, 2011 at 11:55 UTC
    I would speculate that crond is waiting for one for more of the STDIN/STDOUT/STDRR...

    That's right.  crond is generally attempting to read output from the jobs it started, which it would then typically try to mail somewhere.  (This is kind of like if you were to run your script using backticks from another Perl script (or the shell, unless it auto-reaps) — which would produce the exact same behavior of leaving a zombie behind.)

    As the (grand)child process inherits the standard file handles, they're not being closed when the parent part of your script exits, i.e. the child's duplicates remain open.

    The solution is to close those handles, or more properly, do as described in perlipc.

      thanks for the background and link.

      I remember this same issue years ago with a cgi-script used to start a daemon process, but kept the browser progress waiting, even tho the request had "finished".

      I just closed STDIN/OUT/ERR in the child before it does anything.
Re^2: daemon/fork: defunct parent not going away nicely
by Cagao (Monk) on Oct 14, 2011 at 11:39 UTC
    Cheers Dave,

    That sounds very familiar now, needing to close then re-open filehandles, specifically stdin/out/err.