There are two possible error scenarios for CallPgrep. One indicates a broken
system (no pgrep command) and one is a normal error state of pgrep meaning no processes found for the criteria given (in this case the parent pid does not exist or the process simply has no children). The later case is quite usefull to know about so I added a static error for this case.
This commit is contained in:
parent
cc040ddf72
commit
21daedd6b4
|
@ -3,11 +3,14 @@
|
|||
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.
|
||||
|
@ -48,7 +51,7 @@ func CallPgrep(invoke Invoker, pid int32) ([]int32, error) {
|
|||
}
|
||||
out, err := invoke.Command(pgrep, cmd...)
|
||||
if err != nil {
|
||||
return []int32{}, err
|
||||
return []int32{}, ErrorNoChildren
|
||||
}
|
||||
lines := strings.Split(string(out), "\n")
|
||||
ret := make([]int32, 0, len(lines))
|
||||
|
|
Loading…
Reference in New Issue