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 Fork(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 void set_id(pid_t
id) { m_pid = id; }
56 bool isAlive()
const {
return kill(0); }
57 bool kill(
int signo)
const
59 if (m_pid < 0)
return false;
60 return ::kill(m_pid, signo) == 0;
62 bool wait(
int opt = 0)
64 if (m_pid < 0)
return false;
65 if (::waitpid(m_pid, NULL, opt)) {
70 bool cancel() {
return kill(SIGINT); }
Abstract base class for different kinds of events.