Re: A bit of PG archeology uncovers an interesting Linux/Unix factoid - Mailing list pgsql-hackers

From Chapman Flack
Subject Re: A bit of PG archeology uncovers an interesting Linux/Unix factoid
Date
Msg-id 56C27277.6080108@anastigmatix.net
Whole thread Raw
In response to A bit of PG archeology uncovers an interesting Linux/Unix factoid  (Greg Stark <stark@mit.edu>)
Responses Re: A bit of PG archeology uncovers an interesting Linux/Unix factoid
List pgsql-hackers
On 02/15/16 13:42, Greg Stark wrote:

>     (it returns error with errno ECHILD upon successful completion of commands).
>     This fix ignores an error from system() if errno == ECHILD.
> 
> It looks like Linux now behaves similarly,

It seems to be official, in the Single Unix Specification:
http://pubs.opengroup.org/onlinepubs/7908799/xsh/sigaction.html

SA_NOCLDWAIT   If set, and sig equals SIGCHLD, child processes of the calling   processes will not be transformed into
zombieprocesses when they   terminate. If the calling process subsequently waits for its   children, and the process
hasno unwaited for children that were   transformed into zombie processes, it will block until all of its   children
terminate,and wait(), wait3(), waitid() and waitpid() will   fail and set errno to [ECHILD]. Otherwise, terminating
child  processes will be transformed into zombie processes, unless SIGCHLD   is set to SIG_IGN.
 

> So just in case anyone else wants to use system() in Postgres or
> indeed any other Unix application that twiddles with the SIGCHILD
> handler this is something to beware of. It's not entirely clear to me
> that the mention of SA_NOCLDWAIT is the only way to get this
> behaviour, at least one stackoverflow answer implied just setting
> SIG_IGN was enough.

Yup:

• If a process sets the action for the SIGCHLD signal to SIG_IGN, the   behaviour is unspecified, except as specified
below.If the action   for the SIGCHLD signal is set to SIG_IGN, child processes of the   calling processes will not be
transformedinto zombie processes when   they terminate. If the calling process subsequently waits for its   children,
andthe process has no unwaited for children that were   transformed into zombie processes, it will block until all of
its  children terminate, and wait(), wait3(), waitid() and waitpid() will   fail and set errno to [ECHILD].
 

-Chap



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Re: [COMMITTERS] pgsql: Introduce group locking to prevent parallel processes from deadl
Next
From: Tom Lane
Date:
Subject: Re: Re: [COMMITTERS] pgsql: Introduce group locking to prevent parallel processes from deadl