c++boostboost-asioboost-process

Stop child processes after main program exits c++


After the completion of the parent's work, is the child still alive? If so, how can I kill him if the main process is complete? I used boost libraries (boost process, boost asio). If it possible it should be a solution for MacOs, Windows and Linux.

boost::asio::io_service ioservice;
namespace bp = boost::process;
bp::child c(args);
ioservice.run();
c.wait();
result = c.exit_code();

Solution

  • "after" it exits is probably challenging, but you could do it before it exits (or "as" it exits) easily. Send each child an explicit message to shutdown via a pipe, for example. Or, on most operating systems you could just send them a TERM signal.

    You can register an atexit handler to do this but I would keep it simple and just put this feature on the program's natural exit point(s).

    On the flip side, you could have children periodically check for their parent's status and exit if it's missing.