IsProcessUp deleted and was replaced by GetProcessPIDs.
This commit is contained in:
parent
98bb98ffed
commit
299e353c94
@ -2,9 +2,6 @@ package prog
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"os/exec"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProcessList is a map of processes' statuses.
|
// ProcessList is a map of processes' statuses.
|
||||||
@ -47,24 +44,3 @@ func (l ProcessList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|||||||
|
|
||||||
return e.EncodeToken(start.End())
|
return e.EncodeToken(start.End())
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsProcessUp returns true if process is up, and a list of PIDs for
|
|
||||||
// that process name. Uses pgrep to get PID of a process and if
|
|
||||||
// a process is not working, then pgrep returns nothing.
|
|
||||||
func IsProcessUp(name string) (bool, []int, error) {
|
|
||||||
out, err := exec.Command("pgrep", "-f", name).Output()
|
|
||||||
if err != nil || len(out) < 2 {
|
|
||||||
return false, nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
spids := strings.Split(string(out[:len(out)-1]), "\n")
|
|
||||||
pids := make([]int, len(spids))
|
|
||||||
for i, v := range spids {
|
|
||||||
pids[i], err = strconv.Atoi(v)
|
|
||||||
if err != nil {
|
|
||||||
return false, nil, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true, pids, nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user