PROC_SET_PDEATHSIG to get a signal when your parent exits
Thomas Munro
munro at ip9.org
Sat Apr 14 04:44:55 UTC 2018
Hello,
In PostgreSQL we are planning to make use of Linux's
prctl(PR_SET_PDEATHSIG) facility which tells the kernel to signal you
when your parent process exits. This will cut down on polling and
contention on a pipe in certain busy loops, where we need to be able
to exit quickly if something kills the main supervisor process but we
aren't waiting in kevent/epoll/poll-type primitive. We considered
SIGIO but that'd require either one pipe per child process or a common
process group, neither of which works for us. So I decided to try
adding a new command PROC_SET_PDEATHSIG to procctl() to work exactly
like Linux.
Please see attached early draft patch. This is my first attempt at
writing a patch for FreeBSD, so I expect that it contains newbie
mistakes and style problems and I would be grateful for any feedback.
Is this design sane? Is that the best syscall to use for this? Did I
get the ptrace/orphan stuff right? Should this somehow share
something with the Linux compat support for prctl(PR_SET_PDEATHSIG,
...)? Would people want this?
Here's a quick and dirty userspace program I came up with while
developing the patch:
https://github.com/macdice/test-deathsig/blob/master/test-deathsig.c
That tests a few interesting cases I thought of, but note that I
haven't yet tested 32 bit support or the setuid/getuid logic.
Thanks for reading,
Thomas Munro
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Support-PROC_SET_PDEATHSIG-as-a-command-to-procct-v1.patch
Type: application/octet-stream
Size: 8002 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20180414/23e006dd/attachment.obj>
More information about the freebsd-hackers
mailing list