I am writing a library that uses fork()
and exec()
to run external programs.
The code in my library runs as a separate thread.
The library thread needs to waitpid()
on the forked process to know the exit code of the child process.
Unfortunately if the application using my library register a signal handler for SIGCHLD
, the waitpid()
calls returns with an error ECHILD
.
How do I deal with this as a library with the application having minimal impact? I essentially want the child to remain a zombie and have control over when it's reaped.
Can I insulate myself from what the application decides to do?
Can I hijack the signal handler in some way and put it back after my waitpid
is done?