Skip to content

Commit

Permalink
Merge pull request #68 from leahneukirchen/comm
Browse files Browse the repository at this point in the history
psgo: use Stat.Comm in processCOMM
  • Loading branch information
vrothberg authored Apr 9, 2020
2 parents 3c5f81c + 8f49609 commit b17148b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 1 addition & 6 deletions psgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,12 +663,7 @@ func processARGS(p *process.Process, ctx *psContext) (string, error) {

// processCOMM returns the command name (i.e., executable name) of process p.
func processCOMM(p *process.Process, ctx *psContext) (string, error) {
// ps (1) returns "[$name]" if command/args are empty
if p.CmdLine[0] == "" {
return processName(p, ctx)
}
spl := strings.Split(p.CmdLine[0], "/")
return spl[len(spl)-1], nil
return p.Stat.Comm, nil
}

// processNICE returns the nice value of process p.
Expand Down
9 changes: 6 additions & 3 deletions psgo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,21 @@ func TestProcessARGS(t *testing.T) {

func TestProcessCOMM(t *testing.T) {
p := process.Process{
Status: proc.Status{
Name: "foo-bar",
Stat: proc.Stat{
Comm: "foo-bar",
},
CmdLine: []string{""},
}

ctx := new(psContext)
comm, err := processCOMM(&p, ctx)
assert.Nil(t, err)
assert.Equal(t, "[foo-bar]", comm)
assert.Equal(t, "foo-bar", comm)

p = process.Process{
Stat: proc.Stat{
Comm: "foo-bar",
},
CmdLine: []string{"/usr/bin/foo-bar"},
}

Expand Down

0 comments on commit b17148b

Please sign in to comment.