1
0
httpprocprobed/util.go
Alexander "Arav" Andreev 16a60ae504
[util.go] It is better to see in a cmdline, rather than in comm.
For example, matrix synapse in comm has just python3. So lets look in both comm and cmdline.
2022-01-03 01:08:52 +04:00

34 lines
539 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 {
pid, err := strconv.Atoi(entry.Name())
if entry.IsDir() && err == nil {
f, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
if err != nil {
return nil, err
}
if strings.Contains(string(f[:len(f)-1]), name) {
pids = append(pids, pid)
}
}
}
return pids, nil
}