Skip to content

Commit

Permalink
Merge pull request #121 from jimmidyson/stat-brackets-process-name
Browse files Browse the repository at this point in the history
Handle process filenames with spaces in the name
  • Loading branch information
shirou committed Dec 7, 2015
2 parents 759e96e + 7e4cef7 commit fc932d9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,26 +582,31 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32
}
fields := strings.Fields(string(contents))

i := 1
for !strings.HasSuffix(fields[i], ")") {
i++
}

termmap, err := getTerminalMap()
terminal := ""
if err == nil {
t, err := strconv.ParseUint(fields[6], 10, 64)
t, err := strconv.ParseUint(fields[i+5], 10, 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
terminal = termmap[t]
}

ppid, err := strconv.ParseInt(fields[3], 10, 32)
ppid, err := strconv.ParseInt(fields[i+2], 10, 32)
if err != nil {
return "", 0, nil, 0, 0, err
}
utime, err := strconv.ParseFloat(fields[13], 64)
utime, err := strconv.ParseFloat(fields[i+12], 64)
if err != nil {
return "", 0, nil, 0, 0, err
}

stime, err := strconv.ParseFloat(fields[14], 64)
stime, err := strconv.ParseFloat(fields[i+13], 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
Expand All @@ -613,7 +618,7 @@ func (p *Process) fillFromStat() (string, int32, *cpu.CPUTimesStat, int64, int32
}

bootTime, _ := host.BootTime()
t, err := strconv.ParseUint(fields[21], 10, 64)
t, err := strconv.ParseUint(fields[i+20], 10, 64)
if err != nil {
return "", 0, nil, 0, 0, err
}
Expand Down

0 comments on commit fc932d9

Please sign in to comment.