34 lines
561 B
Go
34 lines
561 B
Go
package main
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
func GetProcessPIDs(name string) ([]int, error) {
|
|
var pids []int
|
|
|
|
dir, err := ioutil.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, _ := strconv.Atoi(entry.Name())
|
|
pids = append(pids, pid)
|
|
}
|
|
}
|
|
}
|
|
|
|
return pids, nil
|
|
}
|