Re: Trigger that spawns forked process

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Christopher Murtagh <christopher(dot)murtagh(at)mcgill(dot)ca>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>, Douglas McNaught <doug(at)mcnaught(dot)org>, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Trigger that spawns forked process
Date: 2005-05-10 22:08:38
Message-ID: 20050510220831.GD19068@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, May 10, 2005 at 05:31:56PM -0400, Christopher Murtagh wrote:
> > I'm not sure what happens when you do "exit" here, but I'll lay odds
> > against it being exactly the right things.
>
> It ends the daemonized process, kinda like a wrapper suicide. :-)

I think you have a problem here. PostgreSQL is a complete program,
which use signal, atexit handlers, callback all or which fork()
preserves. When your "little daemon" exits it may trigger all the code
normally run on backend exit, you know, closing WAL files, etc...

The rest of the program has no idea it's a forked process rather than a
real one. Say the backend had a alarm() set and it goes off in your
forked process. Havoc ensues...

> From my (somewhat limited experience) point of view, I think that this
> plperlu script isn't much different from writing a daemon to receive
> signals via NOTIFY. Instead the script is self daemonizing, and it will
> always run (instead of a couple of NOTIFY's building up and only one
> being sent), which is more in line with what I want.

Except that the daemon will be a client process that uses the database
to do work whereas with the other you're duplicating the server without
telling it and putting your data at risk...

> Sorry, my explanation probably isn't very clear at all, I've been
> writing talk material and my brain is in a totally different space. Feel
> free to deliver any LARTs. :-)

You should never fork() and not exec() a large program unless it knows
you're doing it. Note that exec() doesn't run atexit handlers but
exit() does. Big difference...

Hope this helps,

--
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

Browse pgsql-general by date

  From Date Subject
Next Message Mark Lewis 2005-05-10 22:46:04 Re: [PERFORM] "Hash index" vs. "b-tree index" (PostgreSQL
Previous Message Leif B. Kristensen 2005-05-10 21:57:38 Re: Adventures in Quest for GUI RAD