Documentation
¶
Overview ¶
Package procinfo provides OS-specific process information for the ps builtin.
This package is in builtins/internal/ and is therefore exempt from the builtinAllowedSymbols allowlist check. It may use OS-specific APIs freely.
Index ¶
- Constants
- type Metrics
- type ProcInfo
- func GetByPIDs(ctx context.Context, procPath string, pids []int) ([]ProcInfo, error)
- func GetByPIDsWithMetrics(ctx context.Context, procPath string, pids []int, metrics Metrics) ([]ProcInfo, error)
- func GetSession(ctx context.Context, procPath string) ([]ProcInfo, error)
- func GetSessionWithMetrics(ctx context.Context, procPath string, metrics Metrics) ([]ProcInfo, error)
- func ListAll(ctx context.Context, procPath string) ([]ProcInfo, error)
- func ListAllWithMetrics(ctx context.Context, procPath string, metrics Metrics) ([]ProcInfo, error)
Constants ¶
const DefaultProcPath = procpath.Default
DefaultProcPath is the default path to the proc filesystem.
const MaxCmdLen = 4096
MaxCmdLen caps the process name displayed in the CMD column.
const MaxProcesses = 10_000
MaxProcesses caps slice allocation when listing all processes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Metrics ¶ added in v0.0.24
type Metrics uint32
Metrics identifies optional process measurements. Callers request only the measurements needed by their selected output and sort fields, allowing the Darwin and Windows backends to skip unnecessary per-process queries.
type ProcInfo ¶
type ProcInfo struct {
PID int
PPID int
UID string // username or numeric UID string
State string // single char: R, S, D, Z, T, ...
TTY string // "?" if no controlling terminal
CPU int // integer lifetime-average CPU percentage for -f's C column
STime string // start time (HH:MM or Mon DD)
Time string // cumulative CPU time HH:MM:SS
Cmd string // process command/executable name only; never argv
StartTime time.Time
CPUTime time.Duration
Elapsed time.Duration
RSSKiB uint64
VSZKiB uint64
PMem float64
PCPU float64
Available Metrics
}
ProcInfo holds information about a single process.
func GetByPIDs ¶
GetByPIDs returns process info for the given PIDs. Missing PIDs are silently skipped. procPath is the path to the proc filesystem; pass DefaultProcPath or an empty string to use the default.
func GetByPIDsWithMetrics ¶ added in v0.0.24
func GetByPIDsWithMetrics(ctx context.Context, procPath string, pids []int, metrics Metrics) ([]ProcInfo, error)
GetByPIDsWithMetrics returns process info for the given PIDs and requests the optional measurements in metrics.
func GetSession ¶
GetSession returns processes in the current process session (walks PPID chain from os.Getpid() upward to collect ancestors, plus any processes that share the same session ID when available). procPath is the path to the proc filesystem; pass DefaultProcPath or an empty string to use the default.
func GetSessionWithMetrics ¶ added in v0.0.24
func GetSessionWithMetrics(ctx context.Context, procPath string, metrics Metrics) ([]ProcInfo, error)
GetSessionWithMetrics returns current-session processes and requests the optional measurements in metrics.
func ListAll ¶
ListAll returns all running processes. procPath is the path to the proc filesystem (e.g. "/proc"); pass DefaultProcPath or an empty string to use the default.
func ListAllWithMetrics ¶ added in v0.0.24
ListAllWithMetrics returns all running processes and requests the optional measurements in metrics.