1
0
httpprocprobed/process_unix.go

33 lines
584 B
Go

//go:build unix
// +build unix
package main
import (
"os"
"strings"
)
// IsProcessRuns returns true if there is a process with a given name in cmdline.
func IsProcessRuns(name string) (bool, error) {
dir, err := os.ReadDir("/proc/")
if err != nil {
return false, err
}
for _, entry := range dir {
if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 {
cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
if err != nil {
return false, err
}
if strings.Contains(string(cmdline), name) {
return true, nil
}
}
}
return false, nil
}