From 9019796ee10aef4dd8c8f47c217e1a1e85ace571 Mon Sep 17 00:00:00 2001 From: "Paul Buetow (europa)" Date: Sun, 24 May 2015 21:18:06 +0100 Subject: add Process.Print --- Makefile | 4 +--- main/main.go | 2 +- process/process.go | 10 +++++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index b407aac..8cda6f7 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,2 @@ -all: - go run main.go install: - go install github.com/buetow/gstat + go install github.com/buetow/gstat/main diff --git a/main/main.go b/main/main.go index b8b5d39..d1f031c 100644 --- a/main/main.go +++ b/main/main.go @@ -36,7 +36,7 @@ func main() { for { process, more := <-res if more { - fmt.Println(process.Cmdline) + process.Print() } else { break } diff --git a/process/process.go b/process/process.go index 4420b44..9004349 100644 --- a/process/process.go +++ b/process/process.go @@ -13,6 +13,12 @@ type Process struct { Cmdline string } +func (self *Process) Print() { + fmt.Printf("=====================\n") + fmt.Printf("PID: %d\n", self.Pid) + fmt.Printf("cmdline: %s\n", self.Cmdline) +} + func Gather(res chan<- Process) { re, _ := regexp.Compile("^[0-9]+$") @@ -29,7 +35,9 @@ func Gather(res chan<- Process) { if err != nil { log.Fatal(err) } - res <- Process{Pid: pid, Cmdline: string(bytes)} + if len(bytes) > 0 { + res <- Process{Pid: pid, Cmdline: string(bytes)} + } } } } -- cgit v1.2.3