fork() while connected

Started by Michael Meskesabout 24 years ago3 messages
#1Michael Meskes
meskes@postgresql.org

I was just asked if there are problems if a program forks() while connected
to the backend. Of course both processes will try to access the DB after the
fork. Is this possible at all? If so does it create timing problems? Or
others? I think I never tried.

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

#2Doug McNaught
doug@wireboard.com
In reply to: Michael Meskes (#1)
Re: fork() while connected

Michael Meskes <meskes@postgresql.org> writes:

I was just asked if there are problems if a program forks() while connected
to the backend. Of course both processes will try to access the DB after the
fork. Is this possible at all? If so does it create timing problems? Or
others? I think I never tried.

This will definitely not work. The two processes will stomp all over
each other. They'll be sharing one socket and one backend and both
writing/reading from the socket at random times.

You can open a second connection in the child (don't close the first
one there, or it'll mess up the parent). It's probably best to try to
avoid fork()ing with an open connection altogether.

-Doug
--
Let us cross over the river, and rest under the shade of the trees.
--T. J. Jackson, 1863

#3Michael Meskes
meskes@postgresql.org
In reply to: Doug McNaught (#2)
Re: fork() while connected

On Sun, Jan 06, 2002 at 09:24:21AM -0500, Doug McNaught wrote:

This will definitely not work. The two processes will stomp all over
each other. They'll be sharing one socket and one backend and both
writing/reading from the socket at random times.

That's exactly what I expected. Thanks.

Michael
--
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!