Lists: | pgsql-hackers |
---|
From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Possible substitute for PostmasterIsAlive polling loops |
Date: | 2011-02-23 21:54:20 |
Message-ID: | 7701.1298498060@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
We've touched a few times on trying to get rid of the
sleep-awhile-and-check-for-something-to-do loops in PG's auxiliary
processes, mainly to satisfy people who complain about CPU power
consumption when idle. I can see how most of the something-to-do
checks can be reimplemented using latches, but up to now there
didn't seem to be a good way to get rid of waking up every so often
to check if the postmaster was still there. So it got my attention
when someone mentioned this Linux syscall on a Red Hat mailing list:
NAME
prctl - operations on a process
SYNOPSIS
#include <sys/prctl.h>
int prctl(int option, unsigned long arg2, unsigned long arg3,
unsigned long arg4, unsigned long arg5);
...
The first argument can be:
...
PR_SET_PDEATHSIG (since Linux 2.1.57)
Set the parent process death signal of the calling process to
arg2 (either a signal value in the range 1..maxsig, or 0 to
clear). This is the signal that the calling process will get
when its parent dies. This value is cleared for the child of a
fork(2).
IOW, at least on Linux, you *can* arrange to get a signal when your
parent process dies.
Not sure how ugly it'd be to use this call when available and a time
delay when not, but it's something to think about.
regards, tom lane
From: | Robert Haas <robertmhaas(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Possible substitute for PostmasterIsAlive polling loops |
Date: | 2011-02-24 03:14:47 |
Message-ID: | AANLkTi=VUQYf-x3uc0BbUPFUCCQaC54MZ6G4gZOWCYwE@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Wed, Feb 23, 2011 at 4:54 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> IOW, at least on Linux, you *can* arrange to get a signal when your
> parent process dies.
That's pretty cool.
> Not sure how ugly it'd be to use this call when available and a time
> delay when not, but it's something to think about.
Yeah. It may be worth thinking about whether we want to use the
postmaster-pipe trick someone was proposing. That might be more
portable.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
From: | Florian Pflug <fgp(at)phlo(dot)org> |
---|---|
To: | Robert Haas <robertmhaas(at)gmail(dot)com> |
Cc: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Possible substitute for PostmasterIsAlive polling loops |
Date: | 2011-02-24 16:36:39 |
Message-ID: | 06DE5845-AF8A-465F-A903-6DEBD986F249@phlo.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-hackers |
On Feb24, 2011, at 04:14 , Robert Haas wrote:
> On Wed, Feb 23, 2011 at 4:54 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> IOW, at least on Linux, you *can* arrange to get a signal when your
>> parent process dies.
>
> That's pretty cool.
>
>> Not sure how ugly it'd be to use this call when available and a time
>> delay when not, but it's something to think about.
>
> Yeah. It may be worth thinking about whether we want to use the
> postmaster-pipe trick someone was proposing. That might be more
> portable.
FWIW, I did some experiments which this when it was discussion a while ago.
To actually get a signal when the parent dies, I set the FASYNC flag
on the pipe's receiving end's fd. To be able to signal multiple children
using only one pipe, I set the fd's owner to -getgrp() using
fcntl(F_SETOWN). On both linux and OSX 10.6 this caused SIGIO to be sent
to all processes in the process group once sending end of the pipe was
closed.
I don't have access to any other Unixes to test this on, but I since it
works on OSX chances are high that it'll work on FreeBSD also.
best regards,
Florian Pflug