24namespace MultiProcess {
26int wait_for_child(pid_t child_pid,
bool may_throw,
int retries_before_killing)
29 int patience = retries_before_killing;
33 ::kill(child_pid, SIGKILL);
35 tmp = waitpid(child_pid, &status, WNOHANG);
37 || (-1 == tmp && EINTR == errno)
41 std::cout <<
"Had to send PID " << child_pid <<
" " << (-patience + 1) <<
" SIGKILLs";
45 if (WIFEXITED(status)) {
46 printf(
"exited, status=%d\n", WEXITSTATUS(status));
47 }
else if (WIFSIGNALED(status)) {
48 if (WTERMSIG(status) != SIGTERM) {
49 printf(
"killed by signal %d\n", WTERMSIG(status));
51 }
else if (WIFSTOPPED(status)) {
52 printf(
"stopped by signal %d\n", WSTOPSIG(status));
53 }
else if (WIFCONTINUED(status)) {
54 printf(
"continued\n");
58 if (-1 == tmp && may_throw)
59 throw std::runtime_error(std::string(
"waitpid, errno ") + std::to_string(errno));
69 }
else if (
e.num() == EINTR) {
72 }
else if (
e.num() == EAGAIN) {
85 "handle_zmq_ppoll_error is out of options to handle exception, caught ZMQ::ppoll_error_t had errno %d "
88 throw std::logic_error(buffer);
94std::tuple<std::vector<std::pair<size_t, zmq::event_flags>>,
bool>
97 std::size_t tries = 0;
98 std::vector<std::pair<size_t, zmq::event_flags>> poll_result;
100 bool carry_on =
true;
101 while (carry_on && (tries++ < max_tries)) {
103 printf(
"careful_ppoll try %zu\n", tries);
106 poll_result = poller.
ppoll(-1, &ppoll_sigmask);
114 printf(
"EINTR in careful_ppoll but no SIGTERM received, try %zu\n", tries);
117 printf(
"EAGAIN in careful_ppoll (from either send or receive), try %zu\n", tries);
123 if (tries == max_tries) {
124 printf(
"careful_ppoll reached maximum number of tries, %zu, please report as a bug\n", tries);
126 return std::make_tuple(poll_result,
abort);
static bool sigterm_received()
Wrapper class for polling ZeroMQ sockets.
std::vector< std::pair< size_t, zmq::event_flags > > ppoll(int timeo, const sigset_t *sigmask)
Poll the sockets with ppoll.
std::tuple< std::vector< std::pair< size_t, zmq::event_flags > >, bool > careful_ppoll(ZeroMQPoller &poller, const sigset_t &ppoll_sigmask, std::size_t max_tries=2)
zmq_ppoll_error_response handle_zmq_ppoll_error(ZMQ::ppoll_error_t &e)
int wait_for_child(pid_t child_pid, bool may_throw, int retries_before_killing)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...