2022-01-02 21:30:56 +04:00
|
|
|
package main
|
2022-01-02 05:14:21 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2022-01-02 21:30:56 +04:00
|
|
|
"strings"
|
2022-01-02 05:14:21 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
func GetProcessPIDs(name string) ([]int, error) {
|
|
|
|
var pids []int
|
|
|
|
|
|
|
|
dir, err := ioutil.ReadDir("/proc/")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range dir {
|
2022-01-06 03:22:38 +04:00
|
|
|
if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 {
|
|
|
|
cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
|
2022-01-03 01:10:15 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-01-06 03:22:38 +04:00
|
|
|
if strings.Contains(string(cmdline), name) {
|
|
|
|
pid, _ := strconv.Atoi(entry.Name())
|
2022-01-02 05:14:21 +04:00
|
|
|
pids = append(pids, pid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pids, nil
|
|
|
|
}
|