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 Held(pid int) []string
- func IsBackground(ctx context.Context) bool
- func Kubeconfig(c *exec.Cmd, files []string)
- func LookPath(name string) (string, error)
- func Named(name string, uid int) []int
- func Started(pid int) (time.Time, error)
- func Terminate(pids []int, grace time.Duration)
- func UID(pid int) int
- func WriteBytes(pid int) (int64, error)
- type Process
- type Table
- func (t *Table) Ancestors(pid int) []*Process
- func (t *Table) AnonKiB(pid int) int
- func (t *Table) Children(pid int) []*Process
- func (t *Table) Cwd(pid int) string
- func (t *Table) Descendants(pid int) []*Process
- func (t *Table) Environ(pid int) (map[string]string, error)
- func (t *Table) Orphaned(p *Process) bool
- func (t *Table) Process(pid int) *Process
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 Held ¶ added in v0.136.0
Held returns the paths pid holds: its working directory, its executable and every file it has open, a deleted one by the path it had (readable for the caller's own processes).
func IsBackground ¶ added in v0.38.1
IsBackground reports whether ctx is marked by Background.
func Kubeconfig ¶ added in v0.149.0
Kubeconfig makes c read the kubeconfig files as kubectl merges a KUBECONFIG list; none, c keeps the environment's.
func LookPath ¶ added in v0.108.1
LookPath is exec.LookPath, then the Go tool directories for a bare name PATH lacks: beside the running binary, $GOBIN, every $GOPATH/bin, ~/go/bin and ~/.go/bin, in that order. A systemd user unit, the sandbox broker for one, runs with the service manager's PATH, the distribution's default without the directory go install writes to, where kind and the other Go CLIs live beside beekeeper. A tool found nowhere fails naming the directories looked in; a name with a path separator is exec's alone.
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 Terminate ¶ added in v0.149.0
Terminate sends the processes pids SIGTERM, and SIGKILL to those still alive after grace.
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 NewTable ¶ added in v0.149.0
NewTable is the table of the processes ps, linked by their parents: a process tree built in memory rather than read.
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.
func (*Table) Environ ¶ added in v0.13.1
Environ returns the environment of pid in the table's process tree.