Re: Function written in C, hangs on one machine and not another... - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Function written in C, hangs on one machine and not another...
Date
Msg-id 20051028163653.GE26190@svana.org
Whole thread Raw
In response to Re: Function written in C, hangs on one machine and not another...  (Douglas McNaught <doug@mcnaught.org>)
Responses Re: Function written in C, hangs on one machine and not another...  (Douglas McNaught <doug@mcnaught.org>)
List pgsql-general
On Fri, Oct 28, 2005 at 11:59:03AM -0400, Douglas McNaught wrote:
> Dennis Jenkins <dennis.jenkins@sbcglobal.net> writes:
>
> > Is it safe for the postgres engine to fork()?  Would
> > the child need to close down anything immediately in
> > its main() to avoid corrupting the parent?
>
> I *think* (Tom may correct me) that as long as you don't call into the
> backend code at all in the child process, and don't write to any file
> descriptors other than (properly set-up) stdin and stdout, you'd be
> OK.  The safest thing to do would be to exec() a separate binary that
> does the parsing, but that would incur an additional performace
> penalty.

The things that have screwed me up in the past with pulling tricks like
this are:

1. Program has registered atexit() handlers. _exit() avoids this.
2. Pending stdio output that gets flushed. The backend doesn't use
stdio much so you might be fine here.
3. Signals. Make sure you don't get sent signals that screw state.
Might be wise to block them all, or reset them all to default.

Truly, exec() is the cleanest way to solve all this, it simply replaces
the current process, lock, stock and barrel.

Have a nice day,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

Attachment

pgsql-general by date:

Previous
From: Douglas McNaught
Date:
Subject: Re: Function written in C, hangs on one machine and not another...
Next
From: Douglas McNaught
Date:
Subject: Re: Function written in C, hangs on one machine and not another...