9 #include "system/system_call.h" 10 #include "system/pipe_io.h" 11 #include "mpi/mpi_common.h" 13 #include "ForkedWorkerHandler.h" 17 const std::string& input_string) :
22 std::tie(m_child_pid, m_pipe_write_fd, m_pipe_read_fd) =
26 write_to_pipe(m_pipe_write_fd, input_string);
27 close_check(m_pipe_write_fd);
33 if (m_child_pid) terminate();
36 if (!m_read_done) close_check(m_pipe_read_fd);
39 void ForkedWorkerHandler::terminate()
42 if (!m_child_pid)
return;
45 if ( waitpid_success(m_child_pid, WNOHANG,
m_simulator) )
52 if ( kill(m_child_pid, SIGTERM) )
54 std::runtime_error e(
"an error occurred while trying to terminate " 63 if ( waitpid_success(m_child_pid, WNOHANG,
m_simulator, ignore_error) )
70 if ( kill(m_child_pid, SIGKILL) )
72 std::runtime_error e(
"an error occurred while trying to kill " 77 waitpid_success(m_child_pid, 0,
m_simulator, ignore_error);
88 close_check(m_pipe_read_fd);
virtual bool isDone() override
const Command m_simulator
std::chrono::milliseconds g_kill_timeout
std::string m_output_buffer
virtual ~ForkedWorkerHandler() override
ForkedWorkerHandler(const Command &simulator, const std::string &input_string)