Re: Using connection after fork

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff <threshar(at)torgo(dot)978(dot)org>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-general(at)postgresql(dot)org
Subject: Re: Using connection after fork
Date: 2004-08-10 16:51:25
Message-ID: 29320.1092156685@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff <threshar(at)torgo(dot)978(dot)org> writes:
> I've been bit by this sort of thing before. When you fork() the child
> inherits all the file descriptors , including the one connected to PG.
> But when the child dies that FD will be closed, thus it will also be
> closed in the parent causing "odd behavior". (At least, that is what
> I've seen in my apps)

That would only happen if the child explicitly does PQfinish() before
exiting, so that the backend sees an 'X' (Terminate) command arrive
and therefore cuts the connection from its end.
If the child just exits the pipe or TCP connection will remain open.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rajesh Kumar Mallah 2004-08-10 17:10:05 Re: PostgreSQL 8.0.0 Officially Goes Beta
Previous Message Josué Maldonado 2004-08-10 16:46:46 dump/restore from 7.4.3linux to 8beta1 win32