Skip to content

Commit

Permalink
Merge pull request #144 from weberr13/noChildrenError
Browse files Browse the repository at this point in the history
There are two possible error scenarios for CallPgrep.
  • Loading branch information
shirou committed Feb 9, 2016
2 parents 59b63de + c804a9e commit e774385
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions process/process_linux.go
Expand Up @@ -4,6 +4,7 @@ package process

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
Expand All @@ -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
)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit e774385

Please sign in to comment.