diff --git a/system/os.go b/system/os.go index 641e43f..d1ebb0e 100644 --- a/system/os.go +++ b/system/os.go @@ -252,7 +252,7 @@ func parseProcessInfo(output []byte, pid int) (*ProcessInfo, error) { Memory: fields[2], State: fields[3], User: fields[4], - Cmd: fields[5], + Cmd: strings.Join(fields[5:], " "), } } diff --git a/system/os_test.go b/system/os_test.go index 31e19b1..26c1a0d 100644 --- a/system/os_test.go +++ b/system/os_test.go @@ -2,6 +2,7 @@ package system import ( "os/exec" + "runtime" "strings" "testing" "time" @@ -142,3 +143,21 @@ func TestGetProcessInfo(t *testing.T) { t.Log(processInfo) } + +func TestParseProcessInfo_commandWithSpaces(t *testing.T) { + t.Parallel() + + if runtime.GOOS == "windows" { + t.Skip("parses ps output") + } + + assert := internal.NewAssert(t, "TestParseProcessInfo_commandWithSpaces") + + output := []byte(" PID %CPU %MEM STAT USER COMM\n 4242 0.1 0.2 S root Google Chrome Helper\n") + + info, err := parseProcessInfo(output, 4242) + assert.IsNil(err) + assert.Equal("Google Chrome Helper", info.Cmd) + assert.Equal("root", info.User) + assert.Equal("S", info.State) +}