summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (europa) <paul@buetow.org>2015-05-24 15:39:30 +0100
committerPaul Buetow (europa) <paul@buetow.org>2015-05-24 15:39:30 +0100
commite49ed88439e03c48c369a5517beea4551ee6547b (patch)
tree3a6c831296e2afba9259217b03539bd2f4ac5397
initial
-rw-r--r--README.md1
-rw-r--r--main.go73
2 files changed, 74 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..addc052
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# gstat
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..44ef0ab
--- /dev/null
+++ b/main.go
@@ -0,0 +1,73 @@
+package main
+
+import (
+ "fmt"
+ "io/ioutil"
+ "log"
+ "regexp"
+)
+
+const (
+ STOP = 0
+ GETPIDS = 1
+)
+
+type Program struct {
+ pid int
+ command string
+}
+
+func gstatGatherPids(res chan<- string) {
+ re, _ := regexp.Compile("^[0-9]+$")
+
+ dir, err := ioutil.ReadDir("/proc/")
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ for _, fi := range dir {
+ name := fi.Name()
+ if re.MatchString(name) {
+ res <- name
+ }
+ }
+}
+
+func gstatGather(action <-chan int, done chan<- bool, res chan<- string) {
+ for {
+ switch <-action {
+ case STOP:
+ {
+ done <- true
+ break
+ }
+ case GETPIDS:
+ {
+ gstatGatherPids(res)
+ done <- true
+ }
+ }
+ }
+}
+
+func main() {
+ action := make(chan int)
+ done := make(chan bool)
+ res := make(chan string)
+
+ go gstatGather(action, done, res)
+
+ action <- GETPIDS
+ for {
+ switch <-done {
+ case false:
+ {
+ fmt.Println(<-res)
+ }
+ case true:
+ {
+ break
+ }
+ }
+ }
+}