From 7e4cef7a30976300b42d77f9fab323fde0cb13b9 Mon Sep 17 00:00:00 2001 From: Jimmi Dyson Date: Mon, 7 Dec 2015 09:26:43 +0000 Subject: [PATCH] Handle process filenames with spaces in the name Fixes #120 --- process/process_linux.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index 116de00..f54af9f 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -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 } @@ -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 } -- GitLab