Alexander "Arav" Andreev
c7fe073623
Ditched JSON configuration file. Replaced with simple key = value format. Added indented_output option to format output with indent.
34 lines
536 B
Go
34 lines
536 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() + "/comm")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if strings.Contains(string(f[:len(f)-1]), name) {
|
|
pids = append(pids, pid)
|
|
}
|
|
}
|
|
}
|
|
|
|
return pids, nil
|
|
}
|