diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 21:10:43 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 21:10:43 +0100 |
| commit | 8ff768026dfa04d2e1a2c9c9f4cd8b08642004fa (patch) | |
| tree | c703eb2dbb2c1137fe85a2dd00e659ce549ebee3 /process/process.go | |
| parent | 645d431ba55d26c540ce63d54369dd43c5b43a2c (diff) | |
add packages
Diffstat (limited to 'process/process.go')
| -rw-r--r-- | process/process.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/process/process.go b/process/process.go new file mode 100644 index 0000000..4420b44 --- /dev/null +++ b/process/process.go @@ -0,0 +1,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)} + } + } +} |
