util.go -> proc.go. ioutil.ReadDir -> os.ReadDir. Error handling for dir name convert to int. Added build flags to restrict it to UNIX-like OSs only.
This commit is contained in:
parent
48c7c9a3ea
commit
97a3a01053
@ -1,7 +1,8 @@
|
|||||||
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -10,7 +11,7 @@ import (
|
|||||||
func GetProcessPIDs(name string) ([]int, error) {
|
func GetProcessPIDs(name string) ([]int, error) {
|
||||||
var pids []int
|
var pids []int
|
||||||
|
|
||||||
dir, err := ioutil.ReadDir("/proc/")
|
dir, err := os.ReadDir("/proc/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -23,7 +24,10 @@ func GetProcessPIDs(name string) ([]int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if strings.Contains(string(cmdline), name) {
|
if strings.Contains(string(cmdline), name) {
|
||||||
pid, _ := strconv.Atoi(entry.Name())
|
pid, err := strconv.Atoi(entry.Name())
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
pids = append(pids, pid)
|
pids = append(pids, pid)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user