HTTP service that returns a list of process' names with boolean values that respectively telling us if process is running or not.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
httpprocwatchd/util.go

33 lines
536 B

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
}