perl fork() problem: child exit() kills parent

Discussion in 'Perl Misc' started by sunlight@gmail.com, Nov 26, 2005.

  1. Guest

    I have a standalone Perl 5.6 server, running under redhat linux, that
    occasionally fork()s in order to farm out some of its tasks to a
    separate process. When this occurs, the parent doesn't care about the
    child's status or when it completes.. pretty much doesn't ever want to
    hear from it again. The problem is, when the child completes its work
    and exits, the child's exit call appears to kill the parent as well as
    itself.

    Have verified this by replacing the child's exit() call with a long
    sleep()... in this case, the parent keeps working; in all other cases
    the parent dies when the child calls exit(). Things I've tried that
    have NOT solved the problem:

    - CORE::exit instead of exit() for the child
    - Setting SIG{CHLD} in the parent to 'IGNORE', 'DEFAULT', or a basic
    reaper sub
    - POSIX sigblock in the parent for CHLD, INT, QUIT, etc.
    - Having the child close all filehandles, and undef all object
    references inherited from the parent, before doing any work
    - Debug statements to verify the parent isn't exiting due to errors or
    application logic, or accidentally running an exit() intended for the
    child; the parent just disappears

    The fork from the parent does occur within a perl eval {}; block
    (precompiled, no dynamic perl statements); could this be interfering
    with the child's exit()?
    , Nov 26, 2005
    #1
    1. Advertising

  2. wrote:
    > I have a standalone Perl 5.6 server, running under redhat linux, that
    > occasionally fork()s in order to farm out some of its tasks to a
    > separate process. When this occurs, the parent doesn't care about the
    > child's status or when it completes.. pretty much doesn't ever want to
    > hear from it again. The problem is, when the child completes its work
    > and exits, the child's exit call appears to kill the parent as well as
    > itself.
    >
    > Have verified this by replacing the child's exit() call with a long
    > sleep()... in this case, the parent keeps working; in all other cases
    > the parent dies when the child calls exit(). Things I've tried that
    > have NOT solved the problem:
    >
    > - CORE::exit instead of exit() for the child
    > - Setting SIG{CHLD} in the parent to 'IGNORE', 'DEFAULT', or a basic
    > reaper sub
    > - POSIX sigblock in the parent for CHLD, INT, QUIT, etc.
    > - Having the child close all filehandles, and undef all object
    > references inherited from the parent, before doing any work
    > - Debug statements to verify the parent isn't exiting due to errors or
    > application logic, or accidentally running an exit() intended for the
    > child; the parent just disappears
    >
    > The fork from the parent does occur within a perl eval {}; block
    > (precompiled, no dynamic perl statements); could this be interfering
    > with the child's exit()?


    Try using the POSIX::_exit function instead.



    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Nov 26, 2005
    #2
    1. Advertising

  3. Guest

    wrote:
    > I have a standalone Perl 5.6 server, running under redhat linux, that
    > occasionally fork()s in order to farm out some of its tasks to a
    > separate process. When this occurs, the parent doesn't care about the
    > child's status or when it completes.. pretty much doesn't ever want to
    > hear from it again. The problem is, when the child completes its work
    > and exits, the child's exit call appears to kill the parent as well as
    > itself.


    I've done extensive forking on 5.6 under redhat linux, and have never
    seen this problem (persisting under all the things you've tried). Is this
    consistent or sporadic? If consistent, please try to reduce your code to
    the smallest that replicates the problem and post it.


    >
    > Have verified this by replacing the child's exit() call with a long
    > sleep()... in this case, the parent keeps working; in all other cases
    > the parent dies when the child calls exit(). Things I've tried that
    > have NOT solved the problem:
    >
    > - CORE::exit instead of exit() for the child
    > - Setting SIG{CHLD} in the parent to 'IGNORE', 'DEFAULT', or a basic
    > reaper sub
    > - POSIX sigblock in the parent for CHLD, INT, QUIT, etc.
    > - Having the child close all filehandles, and undef all object
    > references inherited from the parent, before doing any work


    Try double forking.

    > - Debug statements to verify the parent isn't exiting due to errors or
    > application logic, or accidentally running an exit() intended for the
    > child; the parent just disappears


    What is the parent doing immediately before it just disappears? Is it
    always the same thing?


    > The fork from the parent does occur within a perl eval {}; block
    > (precompiled, no dynamic perl statements); could this be interfering
    > with the child's exit()?


    I've never seen it happen.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Nov 26, 2005
    #3
  4. Guest

    "Stan R." <> wrote:
    > wrote:
    > > wrote:

    > [...]
    > >> Have verified this by replacing the child's exit() call with a long
    > >> sleep()... in this case, the parent keeps working; in all other cases
    > >> the parent dies when the child calls exit(). Things I've tried that
    > >> have NOT solved the problem:
    > >>
    > >> - CORE::exit instead of exit() for the child
    > >> - Setting SIG{CHLD} in the parent to 'IGNORE', 'DEFAULT', or a basic
    > >> reaper sub
    > >> - POSIX sigblock in the parent for CHLD, INT, QUIT, etc.
    > >> - Having the child close all filehandles, and undef all object
    > >> references inherited from the parent, before doing any work

    > >
    > > Try double forking.

    >
    > Which is better,
    >
    > exit if not fork and fork;
    >
    > or
    >
    > exit if fork or fork;


    The first is better, as it has the parent and the grand child continue,
    while the intermediate child exits. The second has both the parent and
    intermediate child exit, leaving only the grand-child alive, which makes
    one wonder why one desired to fork in the first place.

    But I wouldn't use the first one either. For one thing, it still leaves
    zombies, avoiding which is one of the reasons to double fork. Also, while
    I like terse programs, that is too terse for me. Finally, it would take a
    bit of tortured logic to decide of you are the (grand)child or the parent.


    > ?
    >
    > (Instead of just 'exit if fork;' (single forking.))



    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Nov 27, 2005
    #4
  5. JTech Guest

    POSIX::_exit did the trick, exiting is working perfectly now. thanks
    for the save!
    JTech, Nov 29, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Noel Dolan
    Replies:
    0
    Views:
    205
    Noel Dolan
    Jul 18, 2004
  2. bsder
    Replies:
    10
    Views:
    503
    Big and Blue
    Dec 2, 2005
  3. kaleem
    Replies:
    8
    Views:
    779
    Tad McClellan
    Dec 14, 2006
  4. Replies:
    0
    Views:
    83
  5. Bitswapper
    Replies:
    5
    Views:
    108
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page