如何在Perl的分叉进程中共享数据库连接? [英] How can I share a database connection across a forked process in Perl?

查看:290
本文介绍了如何在Perl的分叉进程中共享数据库连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在Perl中做了以下程序:

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 ****");

我以为它等待子进程的结束想要这样做,并且会运行它为DB由一个亲过程。

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.

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

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

有什么问题?

推荐答案

有很多东西你必须做,以允许一个子进程使用其父级的DBI处理。请参阅Perl Monks关于 DBI,fork和克隆的文章。

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.

这篇关于如何在Perl的分叉进程中共享数据库连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆