Merge pull request #303 from jcaberio/master

fix truncated process name of linux
This commit is contained in:
shirou 2017-01-17 22:23:17 +09:00 committed by GitHub
commit 26dae1bdee
1 changed files with 14 additions and 2 deletions

View File

@ -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":