When I first learned of this behavior, I immediately replaced all calls to fork() with calls to the following throughout our entire codebase:
int checked_fork() {
const int pid = fork();
if (pid < 0) {
throw std::runtime_error("fork failed");
}
return pid;
}