Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 1 Dec 2023 09:26:51 -0700
From:      Alan Somers <asomers@freebsd.org>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   fork-like functions and async-signal-safety
Message-ID:  <CAOtMX2hi-7PfpPVNUsMxtNaQXx8-7ucAf3hvuH1732u1xPNaBg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
fork() is not async-signal-safe, and therefore can't be used in a
signal handler.  Nor can it be used from a multithreaded program
(unless the child only executes aysnc-signal-safe functions).

_Fork(), OTOH, is async-signal-safe.  According to fork(2), "It can be
used safely from signal handlers, but then no userspace services
(malloc(3) or rtld(1)) are available in the child if forked from
multi-threaded parent."

But can you use malloc and rtld in the child if _Fork was invoked from
a multi-threaded process, but not from a signal handler?  That's not
clear to me.

And what about pdfork?  Neither sigaction(2) nor pdfork(2) specify
whether pdfork is async-signal-safe.  Is it?

FYI the reason I'm asking is that I'm trying to determine whether it
would be possible to make cap_init() async-signal-safe.

-Alan



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAOtMX2hi-7PfpPVNUsMxtNaQXx8-7ucAf3hvuH1732u1xPNaBg>