1
0
Fork 0
httpprocprobed/prog/util.go

33 lines
509 B
Go
Raw Normal View History

package prog
import (
"io/ioutil"
"os"
"strconv"
)
func GetProcessPIDs(name string) ([]int, error) {
var pids []int
dir, err := ioutil.ReadDir("/proc/")
if err != nil {
return nil, err
}
for _, entry := range dir {
pid, err := strconv.Atoi(entry.Name())
if entry.IsDir() && err == nil {
f, err := os.ReadFile("/proc/" + entry.Name() + "/comm")
if err != nil {
return nil, err
}
if name == string(f[:len(f)-1]) {
pids = append(pids, pid)
}
}
}
return pids, nil
}