1
0
Fork 0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
659 B

//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd
package main
import (
"os"
"strconv"
"strings"
)
func GetProcessPIDs(name string) ([]int, error) {
var pids []int
dir, err := os.ReadDir("/proc/")
if err != nil {
return nil, err
}
for _, entry := range dir {
if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 {
cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
if err != nil {
return nil, err
}
if strings.Contains(string(cmdline), name) {
pid, err := strconv.Atoi(entry.Name())
if err != nil {
continue
}
pids = append(pids, pid)
}
}
}
return pids, nil
}