-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathworker.cpp
More file actions
57 lines (53 loc) · 748 Bytes
/
worker.cpp
File metadata and controls
57 lines (53 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef _MPROCESSMANAGER_WORKER_CPP
#define _MPROCESSMANAGER_WORKER_CPP
#include "worker.h"
#include "unistd.h"
Worker::Worker()
:m_pid(0),m_status(false),m_type("")
{
}
Worker::~Worker()
{
int ret;
if (m_status ==true){
wait(&ret);
m_status=false;
}
}
void Worker::start()
{
m_pid=fork();
if (m_pid == 0){
run();
exit(0);
}
else if (m_pid >=0){
m_status=true;
}
else {
throw puts("fork error!");
}
}
void Worker::run()
{
throw puts("You must overwrite this function:run()");
}
void Worker::stop()
{
m_status=false;
// exit(0);
}
void Worker::restart()
{
if (m_status == false){
start();
}
}
string Worker::type(const string& newtype /* ="" */)
{
if (newtype !=""){
m_type = newtype;
}
return m_type;
}
#endif