-
Notifications
You must be signed in to change notification settings - Fork 0
/
processManager.h
108 lines (84 loc) · 2.17 KB
/
processManager.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//
// Created by macskas on 12/12/20.
//
#ifndef NSCA_PROCESSMANAGER_H
#define NSCA_PROCESSMANAGER_H
#include <cstdlib>
#include <ctime>
#include <vector>
#include "network.h"
#include "threadManager.h"
#define PROCESS_MAIN 1
#define PROCESS_CHILD 2
#define PROCESS_STATE_RUNNING 1
#define PROCESS_STATE_NOTRUNNING 2
class child_t {
public:
pid_t pid;
int process_state;
time_t started;
child_t() {
this->pid = 0;
this->process_state = PROCESS_STATE_NOTRUNNING;
this->started = 0;
};
void reset() {
this->setPid(0);
this->setProcessState(PROCESS_STATE_NOTRUNNING);
this->started = 0;
}
void setPid(pid_t mpid) {
this->pid = mpid;
}
void setProcessState(int pstate) {
this->process_state = pstate;
}
void updateStarted() {
time(&this->started);
}
};
class processManager {
private:
static processManager *instance;
int process_mode;
pid_t myPid;
pid_t parentPid;
int maxWorker;
std::vector<child_t*> workers;
int workers_running;
class network* nw;
int lockfd;
int process_internal_id = 0;
time_t started = 0;
public:
volatile bool shutdown_requested;
public:
processManager();
~processManager();
static processManager *getInstance();
void setProcessMode(int);
void setPids();
void setMaxWorker(int);
void setInternalProcessId(int);
int getInternalProcessId();
void setStarted();
time_t getStarted();
void startChild(child_t *, int);
void runWorkers();
void work();
int getProcessMode();
static
void sighandler_proxy(int);
void sigchld_handler(int);
void sigint_handler(int);
void sigusr1_handler(int);
void super_limits();
void super_downgrade();
void shutdown();
void killChilds(int);
void loop();
void reset();
void devnull_output();
int lock(const char*);
};
#endif //NSCA_PROCESSMANAGER_H