diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-06-01 23:19:34 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-06-01 23:19:34 +0100 |
| commit | 5d96f9cb6be59e8c2715c63053dc291940182a6b (patch) | |
| tree | 63196bf8f7ff83d67121e21edacf72d57df6eef1 | |
| parent | 42eceb675e414dbff94178c02d797d2cff8a33ee (diff) | |
Handle proecesses without cmdline
| -rw-r--r-- | process/process.go | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/process/process.go b/process/process.go index a30693d..7c63d37 100644 --- a/process/process.go +++ b/process/process.go @@ -15,6 +15,7 @@ type Process struct { Id string Timestamp int32 Pid int + Comm string Cmdline string Count map[string]int debug string @@ -39,8 +40,18 @@ func new(pidstr string) (Process, error) { return p, err } + if err = utils.Slurp(&p.Comm, fmt.Sprintf("/proc/%d/comm", pid)); err != nil { + return p, err + } + err = utils.Slurp(&p.Cmdline, fmt.Sprintf("/proc/%d/cmdline", pid)) - p.Id = fmt.Sprintf("(%s) %s", pidstr, p.Cmdline) + + if p.Cmdline == "" { + p.Id = fmt.Sprintf("(%s) %s", pidstr, p.Comm) + } else { + p.Id = fmt.Sprintf("(%s) %s", pidstr, p.Cmdline) + } + return p, err } @@ -56,6 +67,7 @@ func (self *Process) gatherRaw(what *string, pathf string) error { func (self *Process) parseRawIo(rawIo string) error { countMap := make(map[string]int) + for _, line := range strings.Split(rawIo, "\n") { keyval := strings.Split(line, ": ") if len(keyval) == 2 { @@ -67,6 +79,7 @@ func (self *Process) parseRawIo(rawIo string) error { } } self.Count = countMap + return nil } @@ -74,8 +87,10 @@ func (self *Process) String() string { str := "=========================\n" str += fmt.Sprintf("PID: %d\n", self.Pid) + str += fmt.Sprintf("Comm: %s\n", self.Comm) str += fmt.Sprintf("Cmdline: %s\n", self.Cmdline) str += fmt.Sprintf("Timestamp: %s\n", self.Timestamp) + for key, val := range self.Count { str += fmt.Sprintf("%s=%d\n", key, val) } |
