Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Alex Rolfe <arolfe at MIT dot EDU>
Subject: Passing a connection across a fork()
Date: Feb 22 1998 8:48PM

I'm writing the back end of a web interface to a Sybase database.  I'm
using middleware which in turn uses the perl module(s) ct_lib to connect
to the database.  In order to
handle multiple requests simultaneously, I fork off a child process to
each request and pass it the connection to the database.  In otherwords,
I have multiple processes using the same connection.  Everything works
fine unless one of the children is killed.  That kills the connections
to the database for all of the processes.  The problem seems to be that
the child closes the database connection when it dies.  The error
message that the other children get is to the effect that the database
connection has been closed.

My questions are:
1) Is is safe to pass a database connection through a fork or am I just
getting lucky?
2) How would I disable the connection closing for all but the parent

The alternatives are
- to open a number of database connections and give one to each child
(though this assumes that passing a connection through a fork is
- to start multiple daemons on multiple ports and let the front end try
to find a free one.

        Alex Rolfe