Skip site navigation (1) Skip section navigation (2)

Re: Function written in C, hangs on one machine and not another...

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Douglas McNaught <doug(at)mcnaught(dot)org>
Cc: Dennis Jenkins <dennis(dot)jenkins(at)sbcglobal(dot)net>,postgresql listserv <pgsql-general(at)postgresql(dot)org>
Subject: Re: Function written in C, hangs on one machine and not another...
Date: 2005-10-28 16:36:56
Message-ID: 20051028163653.GE26190@svana.org (view raw or flat)
Thread:
Lists: pgsql-general
On Fri, Oct 28, 2005 at 11:59:03AM -0400, Douglas McNaught wrote:
> Dennis Jenkins <dennis(dot)jenkins(at)sbcglobal(dot)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(at)svana(dot)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.

In response to

Responses

pgsql-general by date

Next:From: Douglas McNaughtDate: 2005-10-28 16:57:29
Subject: Re: Function written in C, hangs on one machine and not another...
Previous:From: Douglas McNaughtDate: 2005-10-28 15:59:03
Subject: Re: Function written in C, hangs on one machine and not another...

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group