1
0
Fork 0

A Process type and a GetProcessesState() func was moved to main.go.

This commit is contained in:
Alexander Andreev 2024-01-13 03:54:34 +04:00
parent 4f6f018b54
commit 37105a9c8a
Signed by: Arav
GPG Key ID: D22A817D95815393
2 changed files with 23 additions and 22 deletions

23
main.go
View File

@ -18,6 +18,29 @@ var showVersion *bool = flag.Bool("v", false, "show version")
var version string
// Process contains an alias that will be returned when queried, and a process
// name to look for.
// A process is effectively a substring that is being looked in a cmdline file
// in /proc/ dir on unix-like systems.
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
}
func main() {
log.SetFlags(0)
flag.Parse()

View File

@ -1,22 +0,0 @@
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
}