mirror of
https://github.com/shirou/gopsutil.git
synced 2025-04-29 13:49:21 +08:00
Merge pull request #144 from weberr13/noChildrenError
There are two possible error scenarios for CallPgrep.
This commit is contained in:
commit
e77438504d
@ -4,6 +4,7 @@ package process
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -18,6 +19,8 @@ import (
|
|||||||
"github.com/shirou/gopsutil/net"
|
"github.com/shirou/gopsutil/net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var ErrorNoChildren = errors.New("process does not have children")
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PrioProcess = 0 // linux/resource.h
|
PrioProcess = 0 // linux/resource.h
|
||||||
)
|
)
|
||||||
@ -205,6 +208,9 @@ func (p *Process) MemoryPercent() (float32, error) {
|
|||||||
func (p *Process) Children() ([]*Process, error) {
|
func (p *Process) Children() ([]*Process, error) {
|
||||||
pids, err := common.CallPgrep(invoke, p.Pid)
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if pids == nil || len(pids) == 0 {
|
||||||
|
return nil, ErrorNoChildren
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ret := make([]*Process, 0, len(pids))
|
ret := make([]*Process, 0, len(pids))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user