2023-12-15 04:05:34 +04:00
|
|
|
//go:build unix
|
|
|
|
// +build unix
|
|
|
|
|
2022-01-02 21:30:56 +04:00
|
|
|
package main
|
2022-01-02 05:14:21 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2022-01-02 21:30:56 +04:00
|
|
|
"strings"
|
2022-01-02 05:14:21 +04:00
|
|
|
)
|
|
|
|
|
2024-07-07 17:23:21 +04:00
|
|
|
// IsProcessRuns returns true if there is a process with a given name in cmdline.
|
|
|
|
func IsProcessRuns(name string) (bool, error) {
|
2022-10-10 00:10:34 +04:00
|
|
|
dir, err := os.ReadDir("/proc/")
|
2022-01-02 05:14:21 +04:00
|
|
|
if err != nil {
|
2024-07-07 17:23:21 +04:00
|
|
|
return false, err
|
2022-01-02 05:14:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, entry := range dir {
|
2022-01-06 03:22:38 +04:00
|
|
|
if entry.IsDir() && entry.Name()[0]>>0x4&0xf == 0x3 {
|
|
|
|
cmdline, err := os.ReadFile("/proc/" + entry.Name() + "/cmdline")
|
2022-01-03 01:10:15 +04:00
|
|
|
if err != nil {
|
2024-07-07 17:23:21 +04:00
|
|
|
return false, err
|
2022-01-03 01:10:15 +04:00
|
|
|
}
|
|
|
|
|
2022-01-06 03:22:38 +04:00
|
|
|
if strings.Contains(string(cmdline), name) {
|
2024-07-07 17:23:21 +04:00
|
|
|
return true, nil
|
2022-01-02 05:14:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-07 17:23:21 +04:00
|
|
|
return false, nil
|
2022-01-02 05:14:21 +04:00
|
|
|
}
|