From c432d48337d630cf9d0b0f5cf8daa7981ff50f37 Mon Sep 17 00:00:00 2001 From: Jorick Caberio Date: Tue, 17 Jan 2017 09:34:52 +0800 Subject: [PATCH] fix truncated process name of linux --- process/process_linux.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/process/process_linux.go b/process/process_linux.go index 04b336a..5b5c6bc 100644 --- a/process/process_linux.go +++ b/process/process_linux.go @@ -3,23 +3,23 @@ package process import ( + "bufio" "bytes" "encoding/json" "errors" "fmt" "io/ioutil" + "math" "os" "path/filepath" "strconv" "strings" "syscall" - "bufio" "github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/net" - "math" ) var ( @@ -720,6 +720,18 @@ func (p *Process) fillFromStatus() error { switch strings.TrimRight(tabParts[0], ":") { case "Name": p.name = strings.Trim(value, " \t") + if len(p.name) >= 15 { + cmdlineSlice, err := p.CmdlineSlice() + if err != nil { + return err + } + if len(cmdlineSlice) > 0 { + extendedName := filepath.Base(cmdlineSlice[0]) + if strings.HasPrefix(extendedName, p.name) { + p.name = extendedName + } + } + } case "State": p.status = value[0:1] case "PPid", "Ppid":