Skip to content

Commit

Permalink
fix: only append running processes
Browse files Browse the repository at this point in the history
  • Loading branch information
RawanMostafa08 committed Sep 26, 2024
1 parent d3b50c8 commit 0a5aa82
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions pkg/processInfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (l *RealProcLoader) Load(filePath string) (string, error) {
return loadFile(filePath)
}

func setProcInfo(data string) (proc Process, err error) {
func setProcInfo(data string) (proc Process, running bool, err error) {
lines := strings.SplitN(data, "\n", -1)

for _, line := range lines {
Expand All @@ -32,6 +32,13 @@ func setProcInfo(data string) (proc Process, err error) {
parts := strings.Split(line, ":")
value := strings.TrimSpace(parts[1])
proc.PID, err = strconv.Atoi(value)
} else if strings.HasPrefix(line, "State") {

parts := strings.Split(line, ":")
value := strings.TrimSpace(parts[1])
if strings.Contains(value, "R") {
running = true
}
}
}
return
Expand Down Expand Up @@ -69,8 +76,11 @@ func getProcessList(loader Loader) (procs []Process, err error) {
return
}
var process Process
process, err = setProcInfo(data)
procs = append(procs, process)
var running bool
process, running, err = setProcInfo(data)
if running {
procs = append(procs, process)
}
}
return
}

0 comments on commit 0a5aa82

Please sign in to comment.