Using perl 5.8.8 on Cygwin with DBD::Oracle 1.2.3 and DBI 1.609
I have some code attempting to fork and then establish a new DB connection using the process as defined at
DBI, Fork, and clone. It is currently behaving quite strangely though:
sub some_method
{
...
print "CALLING FORKER\n";
my $pid = db_forkin($dbh, \@some_array_of_files);
waitpid($pid, 0);
print "KID'S DONE\n";
...
}
sub db_forkin
{
my $dbh = $_[0];
#dereference array ref
my @scripts_to_execute = @{$_[1]};
my $pid = fork();
if($pid == 0) #i'm a child!
{
Print("*****************CHILD******************\n");
#idiom via http://www.perlmonks.org/?node_id=594175
my $child_dbh = $dbh->clone();
$dbh->{InactiveDestroy} = 1;
$dbh = undef;
my $q = qq(INSERT INTO TEST_TABLE
(FIRST_NAME, LAST_NAME, AGE, GENDER)
VALUES ('ISTHIS', 'WORKING', 30, 'X'));
print("*****************A******************\n\n");
my $sth = $child_dbh->prepare($q);
print("*****************B******************\n\n");
$sth->execute();
print("*****************C******************\n\n");
foreach my $script_name (@scripts_to_execute)
{
print("Executing $script_name within a the fork\n");
}
#once the child process is done, kill it.
print("\n************CHILD IS DYING*************\n\n");
POSIX:_exit(0);
}
else
{
return $pid;
}
}
The output of this is:
CALLING FORKER
*****************CHILD******************
<long pause...>
KID'S DONE
It also appears that the insert statement doesn't occur. Now if I comment out the new steps to create the $child_dbh and just use $dbh, i am able to see ...*A*... Basically as soon as anything database related executes, the whole process seems to be lost.
Has anyone seen this behaviour before? Any suggestions?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.