Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: fork() and defunct children

by kyle (Abbot)
on Feb 12, 2008 at 02:31 UTC ( [id://667495]=note: print w/replies, xml ) Need Help??


in reply to fork() and defunct children

Do you open your $dbh before you fork? If so, the child may be meddling with it. Have a look at DBI, fork, and clone. for the gory details, but the nutshell version is that any connection open when the fork happens will be owned by two processes. This means that when the child exits, it will disconnect the parent's connection. It also means that if they're both trying to use it for access, they're going to get very confused.

A simple way to handle this is not to have a connection open during the fork.

The other way to handle it is to have the child set $dbh->{InactiveDestroy} = 1 and then undef the $dbh.

Replies are listed 'Best First'.
Re^2: fork() and defunct children
by Anonymous Monk on Feb 12, 2008 at 22:50 UTC
    Yes, and yes. But I use InactiveDestroy to prevent the DBH from going away because of the fork. I need to share the handle between the parent and children because the parent might take a global FLUSH TABLES WITH READ LOCK lock and hold it open. During that time the children need to be able to work. I may be able to work around this, though.

      I don't know how (or whether) DBD::mysql handles sharing handles across processes, but I suspect what you're trying to do just won't work. If the parent has a lock, the children will have to respect it.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://667495]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-16 22:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found