I have a thread that starts the boost :: process application, with code that the thread works as follows:
void Service::Run()
{
printf("Starting thread for service ID %i\n", this->sid);
bprocess::pipe pstdIn = create_pipe();
bprocess::pipe pstdOut = create_pipe();
file_descriptor_sink fdSink(pstdIn.sink, close_handle);
file_descriptor_source fdSrc(pstdOut.sink, close_handle);
this->stdIn = new fdistream(fdSink);
this->stdOut = new fdostream(fdSrc);
try
{
child proc = execute(
set_args(this->args),
inherit_env(),
bind_stdin(fdSrc),
throw_on_error()
);
printf("PID: %i\n", proc.pid);
int exit_code = wait_for_exit(proc);
printf("Service died, error code: %i\n", exit_code);
}
catch(boost::system::system_error err)
{
printf("Something went wrong: %s\n", err.what());
}
this->manager->ServiceDie(this->sid);
return;
}
Since this function is blocking, it essentially expects the service to be killed (Externally or as I need, enter via stdin to gracefully stop the application).
I do not know how to write in stdin of a child process. I tried this:
*(this->stdIn) << "stop\n";
inside a public function in a class Servicethat is called in another thread ( Managerclass). However, this does not lead to results.
How can I write in stdin of a child proc?
source
share