8#ifndef _Belle2_Process_h
9#define _Belle2_Process_h
25 template <
class WORKER>
26 static void g_handler_exit(
int,
void* worker)
28 delete (WORKER*)worker;
31 static void g_handler_int(
int) { exit(0); }
36 template<
class WORKER>
37 Process(WORKER* worker,
bool detached =
true)
41 signal(SIGINT, g_handler_int);
43 on_exit(g_handler_exit<WORKER>, (
void*)worker);
47 }
else if (detached) {
54 pid_t get_id()
const {
return m_pid; }
55 pid_t id()
const {
return m_pid; }
56 void set_id(pid_t
id) { m_pid = id; }
57 bool isAlive()
const {
return kill(0); }
58 bool kill(
int signo)
const
60 if (m_pid <= 0)
return false;
61 return ::kill(m_pid, signo) == 0;
63 bool wait(
int opt = 0)
65 if (m_pid < 0)
return false;
66 if ((m_waitpid_result = ::waitpid(m_pid, &m_waitpid_status, opt))) {
71 bool cancel() {
return kill(SIGINT); }
72 int waitpid_result()
const
74 return m_waitpid_result;
76 int waitpid_status()
const
78 return m_waitpid_status;
Abstract base class for different kinds of events.