I'm having some difficulty with a program that establishes a database handle and then forks. When the child process exits, the database handle disconnects. Here's a conceptual example:
#!/usr/bin/perl use strict; use MyDBH; my $dbh = MyDBH->new(); print "Ping: ", $dbh->ping(), "\n"; my $kidpid = fork(); if ($kidpid == 0) { # child process print "Hello world from $$!\n"; exit; } # parent process print "Spawned child process: $kidpid\n"; print "Ping: ", $dbh->ping(), "\n";
Output looks like this:
Ping: 1
Hello world from 7022!
Spawned child process: 7022
Ping:

I think what's happening here is that the database handle's destructor is being called when the child process exits. If I replace the exit() call in the child with an exec() of something, the child process is replaced in memory and the destructor is never called. That seems kind of kludgey to me though, and I'm wondering if there's some other way around this. Is there any other way I can remove the object from the child's space or prevent the destructor from being called? I realize I can disconnect the handle prior to forking and the reestablish it, but I'm hoping there's a cleaner solution.

-Matt


In reply to DBI + fork ... child process kills handle by DrManhattan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.