fork-like functions and async-signal-safety
- Reply: Konstantin Belousov : "Re: fork-like functions and async-signal-safety"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 01 Dec 2023 16:26:51 UTC
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