mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
refactor process refresh
This commit is contained in:
@@ -35,25 +35,26 @@ func (pl procList) refresh(eventCh chan string) error {
|
|||||||
pid := pids[i]
|
pid := pids[i]
|
||||||
_, ok := pl[pid]
|
_, ok := pl[pid]
|
||||||
if !ok {
|
if !ok {
|
||||||
cmd, err := getCmd(pid)
|
pl.addPid(pid, eventCh)
|
||||||
if err != nil {
|
|
||||||
cmd = "???" // process probably terminated
|
|
||||||
}
|
|
||||||
uid, err := getUID(pid)
|
|
||||||
if err != nil {
|
|
||||||
uid = "???"
|
|
||||||
}
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pl procList) addPid(pid int, eventCh chan string) {
|
||||||
|
cmd, err := getCmd(pid)
|
||||||
|
if err != nil {
|
||||||
|
cmd = "???" // process probably terminated
|
||||||
|
}
|
||||||
|
uid, err := getUID(pid)
|
||||||
|
if err != nil {
|
||||||
|
uid = "???"
|
||||||
|
}
|
||||||
|
eventCh <- fmt.Sprintf("UID=%-4s PID=%-6d | %s", uid, pid, cmd)
|
||||||
|
pl[pid] = cmd
|
||||||
|
}
|
||||||
|
|
||||||
func getPIDs() ([]int, error) {
|
func getPIDs() ([]int, error) {
|
||||||
proc, err := procDirReader()
|
proc, err := procDirReader()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user