Skip to content

Commit

Permalink
+ add usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kebe7jun committed Oct 20, 2022
1 parent b114aee commit 18d12f6
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,52 @@
# process-monitor
process-monitor is a Go language library for observing the life cycle of system processes.

## Usage

```go
package main

import (
"fmt"
"os"
"os/signal"
"syscall"

processwatcher "github.com/merbridge/process-watcher"
)

func main() {
w := processwatcher.NewProcessWatcher()
if err := w.Start(); err != nil {
panic(err)
}
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
for {
select {
case e := <-w.Events():
if e.Err != nil {
panic(e.Err)
}
typ := "not-support"
var obj interface{}
switch e.GetType() {
case processwatcher.PROC_EVENT_EXEC:
typ = "exec"
obj = e.GetExec()
case processwatcher.PROC_EVENT_FORK:
typ = "fork"
obj = e.GetFork()
case processwatcher.PROC_EVENT_EXIT:
typ = "exit"
obj = e.GetExit()
}
fmt.Printf("%s: %+v\n", typ, obj)
case <-sigs:
return
}
}
}
```

> Nit: Requires a root user to run, you can run as: `go run -exec sudo ./app`

0 comments on commit 18d12f6

Please sign in to comment.