29const char *
const OksSystem::Process::SYS_EXITS_NAMES[] = {
"command line usage error",
"data format error",
"cannot open input",
"addressee unknown",
"host name unknown",
"service unavailable",
"internal software error",
"okssystem error",
30 "critical OS file missing",
"can't create (user) output file",
"input/output error",
"temp failure; user is invited to retry",
"remote error in protocol",
"permission denied ",
"configuration error" };
44 if ((return_value >= EX__BASE) && (return_value <= EX__MAX))
return SYS_EXITS_NAMES[return_value-EX__BASE];
56 std::ostringstream stream;
59 stream << text <<
'(' << return_value <<
')';
61 stream << return_value ;
85 s_instance->m_process_name = name;
94 m_process_id = ::getpid();
121 m_process_name = name;
135OksSystem::Process::operator pid_t()
const throw() {
150 pid_t pid = ::waitpid(m_process_id,&status,0);
151 if (pid!=m_process_id) {
152 std::string message =
"on process " + this->to_string();
153 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"waitpid", message.c_str() );
155 if (WIFEXITED(status)) {
156 int exit_status = WEXITSTATUS(status);
157 if ((throw_non_zero==
false) || (exit_status==0))
return exit_status;
158 throw OksSystem::TerminationIssue(
ERS_HERE, errno, exit_status);
160 if (WIFSIGNALED(status))
throw OksSystem::SignalIssue(
ERS_HERE,errno,WTERMSIG(status));
161 if (WIFSTOPPED(status))
throw OksSystem::SignalIssue(
ERS_HERE,errno,WSTOPSIG(status));
162 return WEXITSTATUS(status);
170 const int status = ::kill(m_process_id,signal_number);
172 std::string message =
"on process " + this->to_string();
173 throw OksSystem::OksSystemCallIssue(
ERS_HERE, errno,
"kill", message.c_str());
184 const int status = ::kill(m_process_id,0);
194 return m_process_id == other.m_process_id;
233 std::ostringstream stream;
234 if (! m_process_name.empty()) {
235 stream << m_process_name <<
' ';
237 stream <<
"pid: " << m_process_id;
276 return ! a.equals(b);
#define ERS_PRECONDITION(expression)
std::ostream & operator<<(std::ostream &stream, const OksSystem::File &file)
Wrapper for process manipulation.
static const int TERMINATION_WAIT
wait time before deciding a termination signal did not work
static const Process * instance()
static const char *const OK_EXIT_NAME
string to describe 0 exit value
static const char * exit_text(int return_value)
the textual description of standard exit codes
int join(bool throw_non_zero=false) const
Waits for the process to terminate.
bool equals(const Process &other) const
Comparison method.
static const int TEST_BASE_VALUE
first value for test manager exit codes
void signal(int signal) const
Sends a signal to the process.
pid_t m_process_id
process identifier
void terminate() const
Terminate the process.
static const char *const SYS_EXITS_NAMES[]
names for standard system exit values
static void set_name(const std::string &name)
static const int TEST_MAX_VALUE
last value for test manager exit codes
static std::string exit_pretty(int return_value)
bool exists() const
Does the process exist?
static const char *const TEST_EXITS_NAMES[]
names for testing exit values
pid_t process_id() const
the id of the process
static Process * s_instance
singleton instance
std::string m_process_name
process name - only to be used for display
Process()
Builds a process representing the current process.
std::string to_string() const
String conversion method.
bool operator!=(const Host &a, const Host &b)
inequality operator
bool operator==(const Host &a, const Host &b)
equality operator