Documentation
¶
Overview ¶
Package proc identifies local processes by pid plus birth (start) time, so a pid the kernel reused is never taken for the process otag started, and finds their descendants. On macOS it reads the kernel's process table with sysctl (KERN_PROC); it never runs ps. Elsewhere only existence checks work and births are unknown.
A failed or implausible read is an error, never "the process exited": callers treat it as unknown and look again later.
Index ¶
Constants ¶
const TimeFormat = "2006-01-02T15:04:05.000Z"
TimeFormat is the layout of Birth; the same as db.TimeFormat (UTC, milliseconds).
Variables ¶
var ErrUnsupported = errors.New("process table not readable on this system")
ErrUnsupported: the process table cannot be read on this system.
Functions ¶
func All ¶
All returns the whole process table by pid. A table that does not even contain this process is rejected as implausible.
Types ¶
type Process ¶
type Process struct {
PID, PPID, PGID int
UID int // effective user id; -1 when unknown
Birth string // start time (TimeFormat); "" when unknown
Zombie bool // exited, not reaped yet: it runs no code any more
}
Process is one entry of the process table.
func Family ¶
Family returns the processes that belong to the process otag started as pid, born at birth: while it runs, itself, its descendants and the members of its session; after it exited, the members of its session born after it. tmux makes every pane process a session leader (session id = its pid), and macOS never hands out a pid that is still in use as a session or group id, so while a member of that session is left no other process can get the pid. This finds children that were reparented to launchd when their parent died; one that left the session (setsid) is only found through its parent, while that runs. With birth "" (unknown) only a running pid is trusted, as the caller vouches for it (its pane still runs it).