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
 
int m_waitpid_status
 

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]

Process ( WORKER *  worker,
bool  detached = true 
)
inline

Definition at line 37 of file Process.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 }

◆ ~Process()

~Process ( )
inline

Definition at line 51 of file Process.h.

51{}

Member Function Documentation

◆ cancel()

bool cancel ( )
inline

Definition at line 71 of file Process.h.

71{ return kill(SIGINT); }

◆ g_handler_exit()

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 54 of file Process.h.

54{ return m_pid; }

◆ id()

pid_t id ( ) const
inline

Definition at line 55 of file Process.h.

55{ return m_pid; }

◆ isAlive()

bool isAlive ( ) const
inline

Definition at line 57 of file Process.h.

57{ return kill(0); }

◆ kill()

bool kill ( int  signo) const
inline

Definition at line 58 of file Process.h.

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

◆ set_id()

void set_id ( pid_t  id)
inline

Definition at line 56 of file Process.h.

56{ m_pid = id; }

◆ wait()

bool wait ( int  opt = 0)
inline

Definition at line 63 of file Process.h.

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

◆ waitpid_result()

int waitpid_result ( ) const
inline

Definition at line 72 of file Process.h.

73 {
74 return m_waitpid_result;
75 };

◆ waitpid_status()

int waitpid_status ( ) const
inline

Definition at line 76 of file Process.h.

77 {
78 return m_waitpid_status;
79 };

Member Data Documentation

◆ m_pid

pid_t m_pid
private

Definition at line 82 of file Process.h.

◆ m_waitpid_result

int m_waitpid_result
private

Definition at line 83 of file Process.h.

◆ m_waitpid_status

int m_waitpid_status
private

Definition at line 84 of file Process.h.


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