Merge pull request #144 from weberr13/noChildrenError

There are two possible error scenarios for CallPgrep.
This commit is contained in:
shirou 2016-02-09 10:57:08 +09:00
commit e77438504d
1 changed files with 6 additions and 0 deletions

View File

@ -4,6 +4,7 @@ package process
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
@ -18,6 +19,8 @@ import (
"github.com/shirou/gopsutil/net"
)
var ErrorNoChildren = errors.New("process does not have children")
const (
PrioProcess = 0 // linux/resource.h
)
@ -205,6 +208,9 @@ func (p *Process) MemoryPercent() (float32, error) {
func (p *Process) Children() ([]*Process, error) {
pids, err := common.CallPgrep(invoke, p.Pid)
if err != nil {
if pids == nil || len(pids) == 0 {
return nil, ErrorNoChildren
}
return nil, err
}
ret := make([]*Process, 0, len(pids))