1
/*-------------------------------------------------------------------------
4
* routines for signaling the postmaster from its child processes
7
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
8
* Portions Copyright (c) 1994, Regents of the University of California
11
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.18 2004-12-31 22:00:56 pgsql Exp $
13
*-------------------------------------------------------------------------
20
#include "miscadmin.h"
21
#include "postmaster/postmaster.h"
22
#include "storage/pmsignal.h"
23
#include "storage/shmem.h"
27
* The postmaster is signaled by its children by sending SIGUSR1. The
28
* specific reason is communicated via flags in shared memory. We keep
29
* a boolean flag for each possible "reason", so that different reasons
30
* can be signaled by different backends at the same time. (However,
31
* if the same reason is signaled more than once simultaneously, the
32
* postmaster will observe it only once.)
34
* The flags are actually declared as "volatile sig_atomic_t" for maximum
35
* portability. This should ensure that loads and stores of the flag
36
* values are atomic, allowing us to dispense with any explicit locking.
39
static volatile sig_atomic_t *PMSignalFlags;
43
* PMSignalInit - initialize during shared-memory creation
50
PMSignalFlags = (sig_atomic_t *)
51
ShmemInitStruct("PMSignalFlags", NUM_PMSIGNALS * sizeof(sig_atomic_t), &found);
54
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
58
* SendPostmasterSignal - signal the postmaster from a child process
61
SendPostmasterSignal(PMSignalReason reason)
63
/* If called in a standalone backend, do nothing */
64
if (!IsUnderPostmaster)
66
/* Atomically set the proper flag */
67
PMSignalFlags[reason] = true;
68
/* Send signal to postmaster */
69
kill(PostmasterPid, SIGUSR1);
73
* CheckPostmasterSignal - check to see if a particular reason has been
74
* signaled, and clear the signal flag. Should be called by postmaster
75
* after receiving SIGUSR1.
78
CheckPostmasterSignal(PMSignalReason reason)
80
/* Careful here --- don't clear flag if we haven't seen it set */
81
if (PMSignalFlags[reason])
83
PMSignalFlags[reason] = false;
90
* PostmasterIsAlive - check whether postmaster process is still alive
92
* amDirectChild should be passed as "true" by code that knows it is
93
* executing in a direct child process of the postmaster; pass "false"
94
* if an indirect child or not sure. The "true" case uses a faster and
95
* more reliable test, so use it when possible.
98
PostmasterIsAlive(bool amDirectChild)
104
* If the postmaster is alive, we'll still be its child. If it's
105
* died, we'll be reassigned as a child of the init process.
107
return (getppid() == PostmasterPid);
112
* Use kill() to see if the postmaster is still alive. This can
113
* sometimes give a false positive result, since the postmaster's
114
* PID may get recycled, but it is good enough for existing uses
115
* by indirect children.
117
return (kill(PostmasterPid, 0) == 0);
120
return (WaitForSingleObject(PostmasterHandle, 0) == WAIT_TIMEOUT);