I have a boost::process::child
that I terminate by calling the boost::process::child::terminate()
function. No errors are thrown. However, if I monitor the active processes using htop
or similar process monitor, I still see the child process hanging around.
I can reproduce with this code:
#include <boost/process.hpp>
#include <chrono>
#include <thread>
#include <csignal>
#include <cstdlib>
#include <iostream>
#include <string.h>
boost::process::child* g_c;
int
main()
{
boost::process::child c("sleep 100000"); \\Long running process
g_c = &c;
std::this_thread::sleep_for(std::chrono::seconds(5)); \\ Main thread does some other stuff
g_c->terminate(); \\ Terminate long running process
std::cout << "Exiting with exit code " << c.exit_code() << "\n";
std::this_thread::sleep_for(std::chrono::seconds(30)); \\Main thread continues doing other stuff
return c.exit_code();
}
After the "Exiting with exit code ..." message is printed, you should be able to see the sleep 100000
process running using a process manager like htop
until the parent process exits.
Why does boost process stick around after termination? And how can I ensure clean termination of the child?