userver: userver/engine/subprocess/child_process_status.hpp Source File
Loading...
Searching...
No Matches
child_process_status.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/engine/subprocess/child_process_status.hpp
4/// @brief @copybrief engine::subprocess::ChildProcessStatus
5
6#include <chrono>
7#include <string>
8
9#include <userver/utils/traceful_exception.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace engine::subprocess {
14
15/// status of finished subprocess
17 public:
18 ChildProcessStatus(int status, std::chrono::milliseconds execution_time);
19
20 enum class ExitReason { kExited, kSignaled };
21
22 ExitReason GetExitReason() const { return exit_reason_; }
23
24 bool IsExited() const { return exit_reason_ == ExitReason::kExited; }
25
26 /// can be called if `IsExited()` returns true
27 int GetExitCode() const;
28
29 bool IsSignaled() const { return exit_reason_ == ExitReason::kSignaled; }
30
31 /// can be called if `IsSignaled()` returns true
32 int GetTermSignal() const;
33
34 /// Returns execution time for subprocess + time to start it with `execve()`
35 std::chrono::milliseconds GetExecutionTime() const { return execution_time_; }
36
37 private:
38 const std::chrono::milliseconds execution_time_;
39 const ExitReason exit_reason_;
40 const int exit_code_;
41 const int term_signal_;
42};
43
45 public:
46 using utils::TracefulException::TracefulException;
47};
48
49const std::string& ToString(ChildProcessStatus::ExitReason exit_reason);
50
51} // namespace engine::subprocess
52
53USERVER_NAMESPACE_END