1
0
httpprocprobed/prog/util.go

33 lines
509 B
Go

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
}