How can I share a database connection across a forked process in Perl?
Question
I made the following programs in Perl before:
my $db = DBconnection with DB2
if ($pid = fork()) {
#parent
} else {
#child
$db->execute("SELECT ****");
exit;
}
wait();
$db->execute("SELECT ****");
I thought that it waited for the end of the child process to have wanted to do it and would operate it for DB by a pro-process.
In addition, DB is not connected to the contents of the error.
What's wrong?
Solution
There is a lot of stuff you must do to allow a child process to use its parent's DBI handle. See this article on Perl Monks about DBI, fork, and clone.
OTHER TIPS
Try including this line of code in your child block:
$db->{InactiveDestroy} = 1;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow