Merge pull request #303 from jcaberio/master

fix truncated process name of linux
pull/305/head
shirou 9 years ago committed by GitHub
commit 26dae1bdee

@ -3,23 +3,23 @@
package process package process
import ( import (
"bufio"
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"syscall" "syscall"
"bufio"
"github.com/shirou/gopsutil/cpu" "github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/host" "github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/internal/common" "github.com/shirou/gopsutil/internal/common"
"github.com/shirou/gopsutil/net" "github.com/shirou/gopsutil/net"
"math"
) )
var ( var (
@ -720,6 +720,18 @@ func (p *Process) fillFromStatus() error {
switch strings.TrimRight(tabParts[0], ":") { switch strings.TrimRight(tabParts[0], ":") {
case "Name": case "Name":
p.name = strings.Trim(value, " \t") 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": case "State":
p.status = value[0:1] p.status = value[0:1]
case "PPid", "Ppid": case "PPid", "Ppid":

Loading…
Cancel
Save