diff options
author | crupest <crupest@outlook.com> | 2023-02-06 00:18:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2023-02-06 00:18:47 +0800 |
commit | 56f5591ce51b37098d8829f805f0778b36ec18cb (patch) | |
tree | 0c5ffd9d86ce4a002a7c70899eef5a39b4d2efac | |
parent | 9322433fa910acace9b6bd1687cabde25f7c14f9 (diff) | |
download | life-main.tar.gz life-main.tar.bz2 life-main.zip |
linux-run: Reap child when timeout.main
-rw-r--r-- | linux-run/linux-run.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/linux-run/linux-run.cpp b/linux-run/linux-run.cpp index dcb9944..0c3ab15 100644 --- a/linux-run/linux-run.cpp +++ b/linux-run/linux-run.cpp @@ -132,6 +132,20 @@ void run(const std::string &program, std::vector<std::string> arguments, if (poll_return == 0) { kill(pid, SIGKILL); + + if (options.stop_reason) { + *options.stop_reason = StopReason::Killed; + } + + if (options.before_reap_callback) { + options.before_reap_callback(pid); + } + + // Reap child process. + if (waitpid(pid, nullptr, 0) == -1) { + throw std::runtime_error("Failed to reap child process. Reason: " + + get_errno_message()); + } throw TimeoutError("Timeout to run command."); } else if (poll_return == -1) { if (errno == EINTR) { |