Re: Win32 question: getppid() with no parent?

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: Magnus Hagander <mha(at)sollentuna(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PgSql-Win32 <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: Win32 question: getppid() with no parent?
Date: 2004-05-27 18:10:06
Message-ID: 200405271810.i4RIA6g20823@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32


Seems we removed a few getppid() calls in January:

http://archives.postgresql.org/pgsql-patches/2004-01/msg00123.php

I agree --- I don't like the pipe usage we have now.

---------------------------------------------------------------------------

Magnus Hagander wrote:
> >On Unix, it is possible to tell whether your parent process has died
> >by checking to see if you have become a child of init:
> >
> > if (getppid() == 1)
> > /* oh dear, I am an orphan */
> >
> >Is there equivalent functionality available on Windows?
> >
> >Currently, we have the pgstat child process checking for postmaster
> >death by watching for read-ready on a pipe. This does not scale
> >pleasantly to multiple long-lived postmaster children, though, so
> >I'm wondering about ways for the children to detect a postmaster crash
> >without requiring any direct postmaster cooperation.
>
> Not really.
> http://www.codeguru.com/Cpp/W-P/win32/article.php/c1437/
> Can be done, but that's really ugly.
>
> Question though - we keep a PostmasterPid variable, right? One way to do
> it is if we n child startup do OpenProcess() on this pid, to return a
> HANDLE (the pid may be reused, but an open handle certainly can't). We
> can then do a simple:
> if (WaitForSingleObject(PostmasterHandle, 0) == WAIT_OBJECT_0)
> /* oh dear, postmaster is gone */
>
> This exepects that we know whom our parent is at process start, which
> gettpid doesn't. But it might be enough?
>
>
> (If we can't rely on that variable, we could do a win32 specific hack
> that passes the HANDLE of the postmaster down to the child on exec, I
> guess.)
>
> //Magnus
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073

In response to

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Magnus Hagander 2004-05-27 18:14:37 Re: Win32 question: getppid() with no parent?
Previous Message Tom Lane 2004-05-27 18:04:52 Re: Win32 question: getppid() with no parent?