|
template<class WORKER > |
| Fork (WORKER *worker, bool detached=true) |
|
pid_t | get_id () const |
|
void | set_id (pid_t id) |
|
bool | isAlive () const |
|
bool | kill (int signo) const |
|
bool | wait (int opt=0) |
|
bool | cancel () |
|
Definition at line 22 of file Fork.h.
◆ Fork() [1/2]
◆ Fork() [2/2]
Fork |
( |
WORKER * |
worker, |
|
|
bool |
detached = true |
|
) |
| |
|
inline |
Definition at line 37 of file Fork.h.
38 {
39 m_pid = fork();
40 if (m_pid == 0) {
41 signal(SIGINT, g_handler_int);
42 if (detached) {
43 on_exit(g_handler_exit<WORKER>, (void*)worker);
44 }
45 worker->run();
46 exit(0);
47 } else if (detached) {
48 delete worker;
49 }
50 }
◆ ~Fork()
◆ cancel()
Definition at line 70 of file Fork.h.
70{ return kill(SIGINT); }
◆ g_handler_exit()
static void g_handler_exit |
( |
int |
, |
|
|
void * |
worker |
|
) |
| |
|
inlinestatic |
Definition at line 26 of file Fork.h.
27 {
28 delete(WORKER*)worker;
29 exit(0);
30 }
◆ g_handler_int()
static void g_handler_int |
( |
int |
| ) |
|
|
inlinestatic |
◆ get_id()
◆ isAlive()
◆ kill()
bool kill |
( |
int |
signo | ) |
const |
|
inline |
Definition at line 57 of file Fork.h.
58 {
59 if (m_pid < 0) return false;
60 return ::kill(m_pid, signo) == 0;
61 }
◆ set_id()
◆ wait()
Definition at line 62 of file Fork.h.
63 {
64 if (m_pid < 0) return false;
65 if (::waitpid(m_pid, NULL, opt)) {
66 m_pid = -1;
67 }
68 return true;
69 }
◆ m_pid
The documentation for this class was generated from the following file: