Documentation
¶
Overview ¶
Package proc reads the Linux process table from /proc once and answers the questions beekeeper asks of it: who is whose parent, which session a process belongs to, how long it has run. Reading /proc directly instead of grepping `ps` output means a pattern never matches the command that looks for it.
Index ¶
- Constants
- func Alive(pid int) bool
- func AnonKiB(pid int) int
- func Background(ctx context.Context) context.Context
- func Cgroup(pid int) string
- func Command(ctx context.Context, name string, arg ...string) *exec.Cmd
- func Cwd(pid int) string
- func Environ(pid int) (map[string]string, error)
- func IsBackground(ctx context.Context) bool
- func Named(name string, uid int) []int
- func Started(pid int) (time.Time, error)
- func UID(pid int) int
- func WriteBytes(pid int) (int64, error)
- type Process
- type Table
Constants ¶
const Niceness = "10"
Niceness is the nice level of a command started under a Background context: behind every interactive process on a starved machine.
Variables ¶
This section is empty.
Functions ¶
func AnonKiB ¶
AnonKiB returns the anonymous resident memory of pid in KiB: what killing it would give back.
func Background ¶ added in v0.38.1
Background marks ctx: the commands Command starts under it run at nice Niceness.
func Command ¶ added in v0.38.1
Command is exec.CommandContext for a read the caller can do without: under a Background context it runs through nice (when the machine has it), and a command killed by ctx gives up its pipes after waitDelay.
func IsBackground ¶ added in v0.38.1
IsBackground reports whether ctx is marked by Background.
func Named ¶ added in v0.101.0
Named returns the PIDs of the live processes whose command name (comm) is name and which run as uid.
func WriteBytes ¶ added in v0.100.0
WriteBytes is what the live process pid caused to be written to storage (write_bytes of /proc/<pid>/io); another user's process is unreadable.
Types ¶
type Process ¶
type Process struct {
PID int
PPID int
Comm string
Args []string
Start time.Time
// StartTicks is Start as the kernel counts it: clock ticks since boot.
StartTicks int64
// CPU is the processor time it has burned (user and system).
CPU time.Duration
// RSSKiB is its resident memory, file-backed pages included.
RSSKiB int
}
Process is one entry of the table.
type Table ¶
Table is a snapshot of the process table.
func ReadAt ¶ added in v0.13.1
ReadAt scans the process tree under root: /proc, or a copy of it (each process's stat, cmdline and environ, and the btime line of stat) captured into testdata.
func (*Table) AnonKiB ¶ added in v0.13.1
AnonKiB returns the anonymous resident memory of pid in the table's process tree.
func (*Table) Cwd ¶ added in v0.13.1
Cwd returns the working directory of pid in the table's process tree.
func (*Table) Descendants ¶
Descendants returns every process below pid, depth first.