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));