A Process type and a GetProcessesState() func was moved to main.go.
This commit is contained in:
parent
4f6f018b54
commit
37105a9c8a
23
main.go
23
main.go
@ -18,6 +18,29 @@ var showVersion *bool = flag.Bool("v", false, "show version")
|
|||||||
|
|
||||||
var version string
|
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() {
|
func main() {
|
||||||
log.SetFlags(0)
|
log.SetFlags(0)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
22
process.go
22
process.go
@ -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
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user