1
0
Fork 0

[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.

This commit is contained in:
Alexander Andreev 2022-01-06 03:22:38 +04:00
parent a67ecc9c3d
commit 316c932ac2
Signed by: Arav
GPG Key ID: 1327FE8A374CC86F
1 changed files with 4 additions and 4 deletions

View File

@ -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)
}
}