Skip to content
/ go-ps Public

🐧 find, list, and get information from process in linux with Go

License

Notifications You must be signed in to change notification settings

nothinux/go-ps

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🐧 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.

Go Report Card test status

Documentation

see pkg.go.dev

Installation

$ go get github.com/nothinux/go-ps

Getting Started

Get All Running Process Name

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

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

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

LICENSE

MIT

About

🐧 find, list, and get information from process in linux with Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages