Re: getpid() function

From: Hannu Krosing <hannu(at)tm(dot)ee>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>, Thomas Lockhart <lockhart(at)fourpalms(dot)org>, Karel Zak <zakkr(at)zf(dot)jcu(dot)cz>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: getpid() function
Date: 2002-08-03 12:55:36
Message-ID: 1028379336.2210.8.camel@rh72.home.ee
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On Sat, 2002-08-03 at 01:25, Tom Lane wrote:
> Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> writes:
> > > Perhaps a more relevant question is why are we cluttering the namespace
> > > with any such function at all? What's the use case for it?
>
> > It was requested because it is exposed in libpq and people need it to
> > generate unique names and stuff like that from within psql and
> > functions. Seems like a valid use for the pid.
>
> The sole reason libpq exposes it is so that you can tell a self-notify
> from an incoming notify. (ie, given you are LISTENing on a condition
> that both you and other clients send NOTIFYs for, is this particular
> message one that you sent yourself, or not? Compare the originator PID
> in the NOTIFY message to your backend_pid to find out.) I put that
> feature in back around 6.4, because it allowed some important
> optimizations in an app I had that used LISTEN/NOTIFY a lot.
>
> Since NOTIFY messages aren't even visible at the SQL level, the above is
> not a reason for making PIDs visible at the SQL level.

When I last time showed how backend_pid function can be trivially
defined as

hannu=# create function getpid() returns int
hannu-# as '/lib/libc.so.6','getpid' language 'C';
CREATE
hannu=# select getpid();
getpid
--------
2832
(1 row)

You claimed that NOTIFY uses some _other_ backend id (i.e. not process
id).

But when I now tested it it seems that this is not the case, notify does
use the actual process id.

hannu=# listen a;
LISTEN
hannu=# notify a;
NOTIFY
Asynchronous NOTIFY 'a' from backend with pid 2832 received.

>
> So I'm still unconvinced that we need or want this ...
>

And you can do it trivially as long as we support old-style C functions
anyway.

------------
Hannu

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message snpe 2002-08-03 14:55:21 CVS problem
Previous Message Matthew Kirkwood 2002-08-03 12:46:38 Re: ERROR: Can't Parse "" (PG and PHP on Linux)

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2002-08-03 13:10:44 Re: Table inheritance versus views
Previous Message Curt Sampson 2002-08-03 11:42:46 Re: WAL file location