-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocess.go
62 lines (47 loc) · 1.2 KB
/
process.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
package proc
import (
"os"
"path/filepath"
"strconv"
)
type Process struct {
Status ProcessStatus `json:"status"`
Statm ProcessStatm `json:"statm"`
Stat ProcessStat `json:"stat"`
IO ProcessIO `json:"io"`
Cmdline string `json:"cmdline"`
}
func ReadProcess(pid uint64, path string) (*Process, error) {
var err error
p := filepath.Join(path, strconv.FormatUint(pid, 10))
if _, err = os.Stat(p); err != nil {
return nil, err
}
process := Process{}
var io *ProcessIO
var stat *ProcessStat
var statm *ProcessStatm
var status *ProcessStatus
var cmdline string
if io, err = ReadProcessIO(filepath.Join(p, "io")); err != nil {
return nil, err
}
if stat, err = ReadProcessStat(filepath.Join(p, "stat")); err != nil {
return nil, err
}
if statm, err = ReadProcessStatm(filepath.Join(p, "statm")); err != nil {
return nil, err
}
if status, err = ReadProcessStatus(filepath.Join(p, "status")); err != nil {
return nil, err
}
if cmdline, err = ReadProcessCmdline(filepath.Join(p, "cmdline")); err != nil {
return nil, err
}
process.IO = *io
process.Stat = *stat
process.Statm = *statm
process.Status = *status
process.Cmdline = cmdline
return &process, nil
}