Well, actually, let's move the platform-independent parts out to a process.go file.
This commit is contained in:
parent
e53bf0b77d
commit
6ba2e8a471
22
process.go
Normal file
22
process.go
Normal file
@ -0,0 +1,22 @@
|
||||
package main
|
||||
|
||||
// Process contains an alias that will be returned when queries, and a process
|
||||
// name to look for.
|
||||
type Process struct {
|
||||
Alias string `json:"alias"`
|
||||
Process string `json:"process"`
|
||||
}
|
||||
|
||||
// ProcessesState is a map of processes' aliases and its statuses.
|
||||
type ProcessesState map[string]bool
|
||||
|
||||
func GetProcessesState(procs *[]Process) (ps ProcessesState) {
|
||||
ps = make(ProcessesState)
|
||||
|
||||
for _, proc := range *procs {
|
||||
pids, err := GetProcessPIDs(proc.Process)
|
||||
ps[proc.Alias] = err == nil && len(pids) > 0
|
||||
}
|
||||
|
||||
return
|
||||
}
|
@ -9,27 +9,6 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Process contains an alias that will be returned when queries, and a process
|
||||
// name to look for.
|
||||
type Process struct {
|
||||
Alias string `json:"alias"`
|
||||
Process string `json:"process"`
|
||||
}
|
||||
|
||||
// ProcessesState is a map of processes' aliases and its statuses.
|
||||
type ProcessesState map[string]bool
|
||||
|
||||
func GetProcessesState(procs *[]Process) (ps ProcessesState) {
|
||||
ps = make(ProcessesState)
|
||||
|
||||
for _, proc := range *procs {
|
||||
pids, err := GetProcessPIDs(proc.Process)
|
||||
ps[proc.Alias] = err == nil && len(pids) > 0
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// GetProcessPIDs returns a list of PIDs found for a process.
|
||||
func GetProcessPIDs(name string) (pids []int, err error) {
|
||||
dir, err := os.ReadDir("/proc/")
|
||||
|
Loading…
Reference in New Issue
Block a user