-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess-promise-tracerd.c
executable file
·78 lines (65 loc) · 1.64 KB
/
process-promise-tracerd.c
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
#include "list.h"
#include "process.h"
#include "basis.h"
#include "signal.h"
#include "config.h"
#include "cpu.h"
#include "log.h"
int main(int argc, char **argv){
if(argc == 2 && strcmp(argv[1], "-c") == 0) // co-operate with systemd service file
exit(config_parse(CONFIG_FILE));
config_init(&cf);
config_read(cf);
cpu_init(&cpu);
cpu_stat(cpu);
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = sighup_handler;
sigaction(SIGHUP, &sa, NULL);
self_pid = getpid();
sprintf(self_name, "%d", self_pid);
List *process_list = malloc(sizeof(List));
if(!process_list){
log_open();
syslog(LOG_ERR, LOG_PREFIX"process list malloc failed");
log_close();
exit(EXIT_FAILURE);
}
LIST_INIT(process_list);
int scan_procfs_period;
Node *iter;
Conf *c;
LIST_FOR_EACH(cf->list, iter){
c = LIST_ENTRY(iter, Conf);
if(0 == strcmp(c->key, "scan_procfs_period")){
sscanf(c->val, "%d", &scan_procfs_period);
break;
}
}
while(1){
usleep(scan_procfs_period);
cpu_stat(cpu); // CPU clock speed changes with its temperature
if(sighup_coming){
sighup_coming = 0;
config_read(cf);
printf("received signal!\n");
}
scan_proc_dir(process_list, PROC_DIR, NULL);
size_t proc_list_size = list_size(process_list);
printf("process count: %zu\n", proc_list_size);
/*
Node *iter;
Process *proc;
int i = 1;
printf("list size: %d\n", list_size(process_list));
LIST_FOR_EACH(process_list, iter){
proc = LIST_ENTRY(iter, Process);
printf("proc %d(%d), state: %c, exec: %s\n", i, proc->pid, proc->state, proc->exe);
i++;
}
*/
}
// never reach here
exit(EXIT_SUCCESS);
}