summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (europa) <paul@buetow.org>2015-05-24 21:18:06 +0100
committerPaul Buetow (europa) <paul@buetow.org>2015-05-24 21:18:06 +0100
commit9019796ee10aef4dd8c8f47c217e1a1e85ace571 (patch)
tree8ce6dc6d3096b6fb1462c3bdb8a1551d950e2431
parent8ff768026dfa04d2e1a2c9c9f4cd8b08642004fa (diff)
add Process.Print
-rw-r--r--Makefile4
-rw-r--r--main/main.go2
-rw-r--r--process/process.go10
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)}
+ }
}
}
}