Documentation ¶
Overview ¶
Package process enumerates the process table for all processes or descendants of a process.
Index ¶
Examples ¶
Constants ¶
const ( // Procfs is the default mount point for procfs filesystems. The default // mountpoint can be changed by setting the PROC environment variable. Procfs = "/proc" ErrSearch = unix.ESRCH // No such process )
Variables ¶
var ( ErrInvalid = fs.ErrInvalid // "invalid argument" ErrNotExist = fs.ErrNotExist // "file does not exist" )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Ps)
func WithProcfs ¶
WithPid sets the location of the procfs mount point.
func WithSnapshot ¶
func WithSnapshot(snapshot SnapshotStrategy) Option
WithSnapshot sets the method for discovering subprocesses.
type ProcChildren ¶
type ProcChildren struct {
*Ps
}
ProcChildren sets the configuration for generating a process snapshot by reading the procfs(5) children file:
A space-separated list of child tasks of this task. Each child task is represented by its TID.
The kernel must be compiled with CONFIG_PROC_CHILDREN enabled.
func (*ProcChildren) Children ¶
func (ps *ProcChildren) Children() ([]int, error)
Children returns the list of subprocesses for a PID by reading /proc/self/task/*/children.
If CONFIG_PROC_CHILDREN is not enabled, the error is set to ErrNotExist.
type Ps ¶
type Ps struct {
// contains filtered or unexported fields
}
Ps contains the state for a process when scanning /proc.
func (*Ps) Children ¶
Children returns a snapshot of the list of subprocesses for a PID by walking /proc.
Example ¶
package main import ( "fmt" "github.com/msantos/goreap/process" ) func main() { ps := process.New(process.WithPid(1)) pids, err := ps.Children() if err != nil { fmt.Println(err) return } fmt.Println(pids) }
Output:
type SnapshotStrategy ¶
type SnapshotStrategy string
const ( SnapshotAny SnapshotStrategy = "" SnapshotPs SnapshotStrategy = "ps" SnapshotChildren SnapshotStrategy = "children" )