如何在Perl中的分叉进程之间共享数据库连接?

时间:2022-11-03 17:01:03

I made the following programs in Perl before:

我之前在Perl中制作了以下程序:

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.

我认为它等待子进程的结束想要这样做并且将通过pro-process为DB操作它。

In addition, DB is not connected to the contents of the error.

此外,DB未连接到错误的内容。

What's wrong?

2 个解决方案

#1


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.

您必须执行许多操作才能允许子进程使用其父进程的DBI句柄。请参阅有关DBI,fork和clone的Perl Monks上的这篇文章。

#2


Try including this line of code in your child block:

尝试在子块中包含以下代码行:

$db->{InactiveDestroy} = 1;

#1


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.

您必须执行许多操作才能允许子进程使用其父进程的DBI句柄。请参阅有关DBI,fork和clone的Perl Monks上的这篇文章。

#2


Try including this line of code in your child block:

尝试在子块中包含以下代码行:

$db->{InactiveDestroy} = 1;