mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 11:44:51 +00:00
42 lines
620 B
Go
42 lines
620 B
Go
package psscanner
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
)
|
|
|
|
type PSScanner struct{}
|
|
|
|
type PSEvent struct {
|
|
UID int
|
|
PID int
|
|
CMD string
|
|
}
|
|
|
|
func (evt PSEvent) String() string {
|
|
uid := strconv.Itoa(evt.UID)
|
|
if evt.UID == -1 {
|
|
uid = "???"
|
|
}
|
|
|
|
return fmt.Sprintf("UID=%-4s PID=%-6d | %s", uid, evt.PID, evt.CMD)
|
|
}
|
|
|
|
func NewPSScanner() *PSScanner {
|
|
return &PSScanner{}
|
|
}
|
|
|
|
func (p *PSScanner) Run(triggerCh chan struct{}) (chan PSEvent, chan error) {
|
|
eventCh := make(chan PSEvent, 100)
|
|
errCh := make(chan error)
|
|
pl := make(procList)
|
|
|
|
go func() {
|
|
for {
|
|
<-triggerCh
|
|
pl.refresh(eventCh)
|
|
}
|
|
}()
|
|
return eventCh, errCh
|
|
}
|