Belle II Software development
Process Class Reference

Public Member Functions

template<class WORKER>
 Process (WORKER *worker, bool detached=true)
 
pid_t get_id () const
 
pid_t id () const
 
void set_id (pid_t id)
 
bool isAlive () const
 
bool kill (int signo) const
 
bool wait (int opt=0)
 
bool cancel ()
 
int waitpid_result () const
 
int waitpid_status () const
 

Static Public Member Functions

template<class WORKER>
static void g_handler_exit (int, void *worker)
 
static void g_handler_int (int)
 

Private Attributes

pid_t m_pid
 
int m_waitpid_result = 0
 
int m_waitpid_status = 0
 

Detailed Description

Definition at line 22 of file Process.h.

Constructor & Destructor Documentation

◆ Process() [1/2]

Process ( )
inline

Definition at line 34 of file Process.h.

34: m_pid(-1) {}

◆ Process() [2/2]

template<class WORKER>
Process ( WORKER * worker,
bool detached = true )
inlineexplicit

Definition at line 37 of file Process.h.

37 : m_pid(fork())
38 {
39 if (m_pid == 0) {
40 signal(SIGINT, g_handler_int);
41 if (detached) {
42 on_exit(g_handler_exit<WORKER>, static_cast<void*>(worker));
43 }
44 worker->run();
45 exit(0);
46 } else if (detached) {
47 delete worker;
48 }
49 }

◆ ~Process()

~Process ( )
inline

Definition at line 50 of file Process.h.

50{}

Member Function Documentation

◆ cancel()

bool cancel ( )
inline

Definition at line 70 of file Process.h.

70{ return kill(SIGINT); }

◆ g_handler_exit()

template<class WORKER>
static void g_handler_exit ( int ,
void * worker )
inlinestatic

Definition at line 26 of file Process.h.

27 {
28 delete (WORKER*)worker;
29 exit(0);
30 }

◆ g_handler_int()

static void g_handler_int ( int )
inlinestatic

Definition at line 31 of file Process.h.

31{ exit(0); }

◆ get_id()

pid_t get_id ( ) const
inline

Definition at line 53 of file Process.h.

53{ return m_pid; }

◆ id()

pid_t id ( ) const
inline

Definition at line 54 of file Process.h.

54{ return m_pid; }

◆ isAlive()

bool isAlive ( ) const
inline

Definition at line 56 of file Process.h.

56{ return kill(0); }

◆ kill()

bool kill ( int signo) const
inline

Definition at line 57 of file Process.h.

58 {
59 if (m_pid <= 0) return false;
60 return ::kill(m_pid, signo) == 0;
61 }

◆ set_id()

void set_id ( pid_t id)
inline

Definition at line 55 of file Process.h.

55{ m_pid = id; }

◆ wait()

bool wait ( int opt = 0)
inline

Definition at line 62 of file Process.h.

63 {
64 if (m_pid < 0) return false;
65 if ((m_waitpid_result = ::waitpid(m_pid, &m_waitpid_status, opt))) {
66 m_pid = -1;
67 }
68 return true;
69 }

◆ waitpid_result()

int waitpid_result ( ) const
inline

Definition at line 71 of file Process.h.

72 {
73 return m_waitpid_result;
74 };

◆ waitpid_status()

int waitpid_status ( ) const
inline

Definition at line 75 of file Process.h.

76 {
77 return m_waitpid_status;
78 };

Member Data Documentation

◆ m_pid

pid_t m_pid
private

Definition at line 81 of file Process.h.

◆ m_waitpid_result

int m_waitpid_result = 0
private

Definition at line 82 of file Process.h.

◆ m_waitpid_status

int m_waitpid_status = 0
private

Definition at line 83 of file Process.h.


The documentation for this class was generated from the following file: