Skip to content

Commit

Permalink
Per suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
weberr13 committed Feb 8, 2016
1 parent 4dcb099 commit c804a9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions internal/common/common_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
package common

import (
"errors"
"os/exec"
"strconv"
"strings"
)

var ErrorNoChildren = errors.New("Process does not have children or does not exist")

func CallLsof(invoke Invoker, pid int32, args ...string) ([]string, error) {
var cmd []string
if pid == 0 { // will get from all processes.
Expand Down Expand Up @@ -51,7 +48,7 @@ func CallPgrep(invoke Invoker, pid int32) ([]int32, error) {
}
out, err := invoke.Command(pgrep, cmd...)
if err != nil {
return []int32{}, ErrorNoChildren
return []int32{}, err
}
lines := strings.Split(string(out), "\n")
ret := make([]int32, 0, len(lines))
Expand Down
4 changes: 2 additions & 2 deletions process/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/shirou/gopsutil/net"
)

var ErrorNoChildren = errors.New("Process does not have children")
var ErrorNoChildren = errors.New("process does not have children")

const (
PrioProcess = 0 // linux/resource.h
Expand Down Expand Up @@ -208,7 +208,7 @@ func (p *Process) MemoryPercent() (float32, error) {
func (p *Process) Children() ([]*Process, error) {
pids, err := common.CallPgrep(invoke, p.Pid)
if err != nil {
if err == common.ErrorNoChildren {
if pids == nil || len(pids) == 0 {
return nil, ErrorNoChildren
}
return nil, err
Expand Down

0 comments on commit c804a9e

Please sign in to comment.