1
0

[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.
This commit is contained in:
Alexander Andreev 2022-01-03 01:10:15 +04:00
parent 16a60ae504
commit cf300b899a
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F

12
util.go
View File

@ -18,7 +18,17 @@ func GetProcessPIDs(name string) ([]int, error) {
for _, entry := range dir { for _, entry := range dir {
pid, err := strconv.Atoi(entry.Name()) pid, err := strconv.Atoi(entry.Name())
if entry.IsDir() && err == nil { if entry.IsDir() && err == nil {
f, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline") f, err := os.ReadFile("/proc/" + entry.Name() + "/comm")
if err != nil {
return nil, err
}
if strings.Contains(string(f[:len(f)-1]), name) {
pids = append(pids, pid)
continue
}
f, err = os.ReadFile("/proc/" + entry.Name() + "/cmdline")
if err != nil { if err != nil {
return nil, err return nil, err
} }