https://github.com/nothinux/go-ps
:penguin: find, list, and get information from process in linux with Go
https://github.com/nothinux/go-ps
go golang linux-process
Last synced: 27 days ago
JSON representation
:penguin: find, list, and get information from process in linux with Go
- Host: GitHub
- URL: https://github.com/nothinux/go-ps
- Owner: nothinux
- License: mit
- Created: 2021-11-11T07:49:40.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-06-09T15:39:21.000Z (over 3 years ago)
- Last Synced: 2024-06-19T19:42:28.623Z (over 1 year ago)
- Topics: go, golang, linux-process
- Language: Go
- Homepage:
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 🐧 go-ps
go-ps is process library for find, list, and get information from linux process. go-ps read information about process from `/proc` file.
[](https://goreportcard.com/report/github.com/nothinux/go-ps) 
## Documentation
see [pkg.go.dev](https://pkg.go.dev/github.com/nothinux/go-ps)
## Installation
```
$ go get github.com/nothinux/go-ps
```
### Getting Started
#### Get All Running Process Name
``` go
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)
}
}
```
#### Find Pid from Process Name
``` go
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)
}
```
#### Find Process then get information from that process
``` go
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)
}
```
[more](https://pkg.go.dev/github.com/nothinux/go-ps)
## LICENSE
[MIT](https://github.com/nothinux/go-ps/blob/master/LICENSE)