blob: 4420b44da949b19166eba97a0800901ce4e01ad0 (
plain)
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
|
package process
import (
"fmt"
"io/ioutil"
"log"
"regexp"
"strconv"
)
type Process struct {
Pid int
Cmdline string
}
func Gather(res chan<- Process) {
re, _ := regexp.Compile("^[0-9]+$")
dir, err := ioutil.ReadDir("/proc/")
if err != nil {
log.Fatal(err)
}
for _, direntry := range dir {
name := direntry.Name()
if re.MatchString(name) {
pid, _ := strconv.Atoi(name)
bytes, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/cmdline", pid))
if err != nil {
log.Fatal(err)
}
res <- Process{Pid: pid, Cmdline: string(bytes)}
}
}
}
|