1
0
Fork 0

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:
Alexander Andreev 2022-10-10 00:10:34 +04:00
parent 48c7c9a3ea
commit 97a3a01053
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F
1 changed files with 7 additions and 3 deletions

View File

@ -1,7 +1,8 @@
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
package main
import (
"io/ioutil"
"os"
"strconv"
"strings"
@ -10,7 +11,7 @@ import (
func GetProcessPIDs(name string) ([]int, error) {
var pids []int
dir, err := ioutil.ReadDir("/proc/")
dir, err := os.ReadDir("/proc/")
if err != nil {
return nil, err
}
@ -23,7 +24,10 @@ func GetProcessPIDs(name string) ([]int, error) {
}
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)
}
}