diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 15:39:30 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 15:39:30 +0100 |
| commit | e49ed88439e03c48c369a5517beea4551ee6547b (patch) | |
| tree | 3a6c831296e2afba9259217b03539bd2f4ac5397 | |
initial
| -rw-r--r-- | README.md | 1 | ||||
| -rw-r--r-- | main.go | 73 |
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 @@ -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 + } + } + } +} |
