diff options
Diffstat (limited to 'src/backend/storage/ipc/pmsignal.c')
-rw-r--r-- | src/backend/storage/ipc/pmsignal.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/backend/storage/ipc/pmsignal.c b/src/backend/storage/ipc/pmsignal.c index b0fc1aea0ff..4efa4adac6f 100644 --- a/src/backend/storage/ipc/pmsignal.c +++ b/src/backend/storage/ipc/pmsignal.c @@ -8,7 +8,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.13 2004/02/08 22:28:56 neilc Exp $ + * $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.14 2004/05/29 22:48:20 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -83,3 +83,41 @@ CheckPostmasterSignal(PMSignalReason reason) } return false; } + +/* + * PostmasterIsAlive - check whether postmaster process is still alive + * + * amDirectChild should be passed as "true" by code that knows it is + * executing in a direct child process of the postmaster; pass "false" + * if an indirect child or not sure. The "true" case uses a faster and + * more reliable test, so use it when possible. + */ +bool +PostmasterIsAlive(bool amDirectChild) +{ +#ifndef WIN32 + if (amDirectChild) + { + /* + * If the postmaster is alive, we'll still be its child. If it's + * died, we'll be reassigned as a child of the init process. + */ + return (getppid() == PostmasterPid); + } + else + { + /* + * Use kill() to see if the postmaster is still alive. This can + * sometimes give a false positive result, since the postmaster's PID + * may get recycled, but it is good enough for existing uses by + * indirect children. + */ + return (kill(PostmasterPid, 0) == 0); + } +#else /* WIN32 */ + /* + * XXX needs to be implemented by somebody + */ + return true; +#endif /* WIN32 */ +} |