Re: [HACKERS] postmaster disappears

From: Bruce Momjian <maillist(at)candle(dot)pha(dot)pa(dot)us>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: t-ishii(at)sra(dot)co(dot)jp, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] postmaster disappears
Date: 1999-09-22 16:39:14
Message-ID: 199909221639.MAA08003@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Do we even need a signal handler at all for ECHILD? I suppose the
> select might not get interrupted (at least on some platforms) if there
> isn't one.
>
> Actually I guess there still is a race condition: there is a window
> between the last wait() of the reap loop and the select() wherein an
> ECHILD won't be serviced right away, because we hit the select() before
> noticing it. We could maybe use a timeout on the select to fix that.
> Don't really like it though, since the timeout couldn't be very long,
> but we don't want the postmaster wasting cycles when there's nothing
> to do. Is there another way around this?

Here is code I use for reaping dead child processes. Under SysV, if you
say you want to ignore child processes, they just disappear, but on BSD,
the children stay as zombies. This fixes that.

Seems you need to define a singnal handler, and just put select() in a
loop:

while (1)
if (select(...) != -1 || errno != EINTR)
break;

I see you are are loosing your error inside the singnal handler. Seems
you may have to save/restore errno.

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

/*
* From: rstevens(at)noao(dot)edu (W. Richard Stevens)
* Newsgroups: comp.unix.bsd.misc,comp.unix.bsd.bsdi.misc
* Subject: Re: BSD 4.4: Preventing zombies SIGCHLD
* Date: 19 Dec 1995 13:24:39 GMT
*/

void
reapchild(int signo)
{
pid_t pid;
int stat;

while ( (pid = waitpid(-1, &stat, WNOHANG)) > 0) {
/* handle "pid" and "stat" */
}
if (pid < 0)
;/* error */

/* we are done playing the current sound */
cur_sound_id = -1;

/* return value is 0 if no more children */
return;
}

--
Bruce Momjian | http://www.op.net/~candle
maillist(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-09-22 16:45:49 Re: [DOCS] INSTALL file (was Re: [HACKERS] Re: HISTORY for 6.5.2)
Previous Message Bruce Momjian 1999-09-22 16:20:56 Re: [HACKERS] Operator definitions