[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:
parent
a67ecc9c3d
commit
316c932ac2
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…
Reference in New Issue
Block a user