The user provided callback may call reaper_del(), in which case we
will crash when we also try to remove the child from the list.
Remove it from the list before the callback means reaper_del() (if
called by the callback) will just loop through the entire list without
finding the pid and thus do nothing.
When calling ‘reaper_add()’, the caller can provide a callback. If
non-NULL, the reaper will call the callback to handle the actual
reaping.
If the callback is NULL, or if it returns false, the reaper reaps the
child process.
Use a signalfd to listen for SIGCHLD signals.
When we receive a SIGCHLD over the signalfd, reap all dead children by
looping over all registered child PIDs and call waitpid(WNOHANG) on
them.