forked from rfjakob/earlyoom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestsuite_c_wrappers.go
82 lines (68 loc) · 1.7 KB
/
testsuite_c_wrappers.go
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
package earlyoom_testsuite
import (
"fmt"
"strings"
)
// #cgo CFLAGS: -std=gnu99 -DCGO
// #include "meminfo.h"
// #include "kill.h"
// #include "msg.h"
// #include "globals.h"
import "C"
func parse_term_kill_tuple(optarg string, upper_limit int) (error, float64, float64) {
cs := C.CString(optarg)
tuple := C.parse_term_kill_tuple(cs, C.longlong(upper_limit))
errmsg := C.GoString(&(tuple.err[0]))
if len(errmsg) > 0 {
return fmt.Errorf(errmsg), 0, 0
}
return nil, float64(tuple.term), float64(tuple.kill)
}
func is_alive(pid int) bool {
res := C.is_alive(C.int(pid))
return bool(res)
}
func fix_truncated_utf8(str string) string {
cstr := C.CString(str)
C.fix_truncated_utf8(cstr)
return C.GoString(cstr)
}
func parse_meminfo() C.meminfo_t {
return C.parse_meminfo()
}
func find_largest_process() {
var args C.poll_loop_args_t
C.find_largest_process(&args)
}
func kill_process() {
var args C.poll_loop_args_t
var victim C.procinfo_t
victim.pid = 1
C.kill_process(&args, 0, &victim)
}
func get_oom_score(pid int) int {
return int(C.get_oom_score(C.int(pid)))
}
func get_oom_score_adj(pid int, out *int) int {
var out2 C.int
res := C.get_oom_score_adj(C.int(pid), &out2)
*out = int(out2)
return int(res)
}
func get_vm_rss_kib(pid int) int {
return int(C.get_vm_rss_kib(C.int(pid)))
}
func get_comm(pid int) (int, string) {
cstr := C.CString(strings.Repeat("\000", 256))
res := C.get_comm(C.int(pid), cstr, 256)
return int(res), C.GoString(cstr)
}
func get_cmdline(pid int) (int, string) {
cstr := C.CString(strings.Repeat("\000", 256))
res := C.get_cmdline(C.int(pid), cstr, 256)
return int(res), C.GoString(cstr)
}
func procdir_path(str string) {
cstr := C.CString(str)
C.procdir_path = cstr
}