refactor process refresh

This commit is contained in:
Dominic Breuker
2018-03-06 09:57:58 +01:00
parent 65ec5b1202
commit a6d948819f

View File

@@ -35,6 +35,14 @@ func (pl procList) refresh(eventCh chan string) error {
pid := pids[i] pid := pids[i]
_, ok := pl[pid] _, ok := pl[pid]
if !ok { if !ok {
pl.addPid(pid, eventCh)
}
}
return nil
}
func (pl procList) addPid(pid int, eventCh chan string) {
cmd, err := getCmd(pid) cmd, err := getCmd(pid)
if err != nil { if err != nil {
cmd = "???" // process probably terminated cmd = "???" // process probably terminated
@@ -44,14 +52,7 @@ func (pl procList) refresh(eventCh chan string) error {
uid = "???" uid = "???"
} }
eventCh <- fmt.Sprintf("UID=%-4s PID=%-6d | %s", uid, pid, cmd) eventCh <- fmt.Sprintf("UID=%-4s PID=%-6d | %s", uid, pid, cmd)
// if print {
// log.Printf("\x1b[31;1mCMD: UID=%-4s PID=%-6d | %s\x1b[0m\n", uid, pid, cmd)
// }
pl[pid] = cmd pl[pid] = cmd
}
}
return nil
} }
func getPIDs() ([]int, error) { func getPIDs() ([]int, error) {