1 #ifndef _Belle2_Process_h
2 #define _Belle2_Process_h
18 template <
class WORKER>
19 static void g_handler_exit(
int,
void* worker)
21 delete(WORKER*)worker;
24 static void g_handler_int(
int) { exit(0); }
29 template<
class WORKER>
30 Process(WORKER* worker,
bool detached =
true)
34 signal(SIGINT, g_handler_int);
36 on_exit(g_handler_exit<WORKER>, (
void*)worker);
40 }
else if (detached) {
47 pid_t get_id()
const {
return m_pid; }
48 pid_t id()
const {
return m_pid; }
49 void set_id(pid_t
id) { m_pid = id; }
50 bool isAlive()
const {
return kill(0); }
51 bool kill(
int signo)
const
53 if (m_pid <= 0)
return false;
54 return ::kill(m_pid, signo) == 0;
56 bool wait(
int opt = 0)
58 if (m_pid < 0)
return false;
59 if (m_waitpid_result = ::waitpid(m_pid, &m_waitpid_status, opt)) {
64 bool cancel() {
return kill(SIGINT); }
65 int waitpid_result()
const
67 return m_waitpid_result;
69 int waitpid_status()
const
71 return m_waitpid_status;