go-ps is process library for find, list, and get information from linux process. go-ps read information about process from /proc
file.
see pkg.go.dev
$ go get github.com/nothinux/go-ps
package main
import (
"log"
"fmt"
"github.com/nothinux/go-ps"
)
func main() {
process, err := ps.GetProcess()
if err != nil {
log.Fatal(err)
}
for _, p := range process {
fmt.Println(p.Comm)
}
}
package main
import (
"log"
"github.com/nothinux/go-ps"
"fmt"
)
func main() {
pid, err := ps.FindPid("nginx")
if err != nil {
log.Fatal(err)
}
fmt.Println(pid)
}
package main
import (
"log"
"github.com/nothinux/go-ps"
"fmt"
)
func main() {
p, err := ps.FindProcessName("nginx")
if err != nil {
log.Fatal(err)
}
fmt.Println("process id:", p.Pid)
fmt.Println("process name:", p.Comm)
fmt.Println("process cmd:", p.CmdLine)
fmt.Println("process state:", p.State)
}