From 0a5aa825348f8866c982600dd73f9cfd564898f3 Mon Sep 17 00:00:00 2001 From: RawanMostafa08 Date: Thu, 26 Sep 2024 12:44:26 +0300 Subject: [PATCH] fix: only append running processes --- pkg/processInfo.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/processInfo.go b/pkg/processInfo.go index 1bd1014..f79aa40 100644 --- a/pkg/processInfo.go +++ b/pkg/processInfo.go @@ -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 { @@ -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 @@ -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 }