Source File
common_unix.go
Belonging Package
github.com/gofiber/fiber/v2/internal/gopsutil/common
//go:build linux || freebsd || darwin || openbsd
package common
import (
)
func ( context.Context, Invoker, int32, ...string) ([]string, error) {
var []string
if == 0 { // will get from all processes.
= []string{"-a", "-n", "-P"}
} else {
= []string{"-a", "-n", "-P", "-p", strconv.Itoa(int())}
}
= append(, ...)
, := exec.LookPath("lsof")
if != nil {
return []string{},
}
, := .CommandWithContext(, , ...)
if != nil {
// if no pid found, lsof returns code 1.
if .Error() == "exit status 1" && len() == 0 {
return []string{}, nil
}
}
:= strings.Split(string(), "\n")
var []string
for , := range [1:] {
if len() == 0 {
continue
}
= append(, )
}
return , nil
}
func ( context.Context, Invoker, int32) ([]int32, error) {
:= []string{"-P", strconv.Itoa(int())}
, := exec.LookPath("pgrep")
if != nil {
return []int32{},
}
, := .CommandWithContext(, , ...)
if != nil {
return []int32{},
}
:= strings.Split(string(), "\n")
:= make([]int32, 0, len())
for , := range {
if len() == 0 {
continue
}
, := strconv.Atoi()
if != nil {
continue
}
= append(, int32())
}
return , nil
}
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |