Browse Source

[util.go] Optimisation by comparing high part of byte to 3 (numbers in ASCII are going from 0x30 to 0x39). And convert the whole number only if it is PID we are looking for.

master
Alexander Andreev 7 months ago
parent
commit
316c932ac2
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
  1. 8
      util.go

8
util.go

@ -16,14 +16,14 @@ func GetProcessPIDs(name string) ([]int, error) {
}
for _, entry := range dir {
pid, err := strconv.Atoi(entry.Name())
if entry.IsDir() && err == nil {
f, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
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(f), name) {
if strings.Contains(string(cmdline), name) {
pid, _ := strconv.Atoi(entry.Name())
pids = append(pids, pid)
}
}

Loading…
Cancel
Save