I wanted to spawn a child process from my application such that their lifetimes are tied i.e. when my application is closed, the child process is also closed. To achieve the same I used boost::process::child::terminate()
.
The problem with using terminate()
is that the spawned child process doesn't know that it is exiting and thus can't take necessary steps to ensure that the exit is clean (close open file handles, release resources etc.).
Without using interprocess communication, is there a way to detect in the child process that it is being terminated or communicate to child this somehow?
I have tried using the following handlers to catch termination at child end, but without any success:
std::set_terminate(terminateHandler);
std::set_unexpected(unexpectedHandler);
SetUnhandledExceptionFilter(sehExceptionHandler);
_set_purecall_handler(pureCallHandler);
_set_new_handler(newMemoryExceptionHandler);
_set_invalid_parameter_handler(invalidParameterHandler);
_set_abort_behavior(_CALL_REPORTFAULT, _CALL_REPORTFAULT);
signal(SIGABRT, abortHandler);
signal(SIGINT, interruptionHandler);
signal(SIGTERM, terminationRequestHandler);
Any thoughts?