Documentation
¶
Overview ¶
Package procstat reads the machine's process table and what each process costs — CPU and resident memory — on macOS, Linux and Windows.
It only reads. Nothing here signals, opens or writes to another process; rule 7 forbids signalling a process Caprock did not start (the doctor's confirmed stop, ADR-059, lives in internal/daemon), and reading the figures a process manager shows is not that.
The table comes from one call where the OS has one (sysctl kern.proc.all on macOS) and from gopsutil elsewhere; per-process CPU time and resident size come from gopsutil on every OS. CPU is a percentage of one core between two samples, so a process tree using three cores reads 300%.
Index ¶
- func Cmdline(ctx context.Context, pid int32) []string
- func Environ(ctx context.Context, pid int32) []string
- func Exe(ctx context.Context, pid int32) string
- func HasTTY(p Proc) bool
- func IsInterpreter(name string) bool
- func Label(name string, argv []string) string
- func ResponsiblePID(int32) int32
- func SelfDiskIO() (read, written uint64, err error)
- func StartMs(ctx context.Context, pid int32) (int64, bool)
- type Proc
- type Sampler
- type Table
- type Usage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cmdline ¶
Cmdline is a process's argument vector; nil when it cannot be read (another user's process, or one that has exited).
func Exe ¶ added in v0.113.0
Exe is the absolute path of a process's executable as the OS reports it (symlinks resolved on macOS and Linux); "" when it cannot be read.
func HasTTY ¶ added in v0.116.0
HasTTY is whether p has a controlling terminal: tty_nr, the seventh field of /proc/<pid>/stat, is not zero. A process that cannot be read says no.
func IsInterpreter ¶ added in v0.116.0
IsInterpreter is whether a program name (as the process table or argv[0] gives it) is an interpreter or a shell that runs a script named after it.
func Label ¶
Label is a short name for a process a person recognises: the program, and for an interpreter the script it runs. name is the fallback when argv is unreadable.
func ResponsiblePID ¶ added in v0.113.0
ResponsiblePID is macOS only; elsewhere a web view's processes are the app's own children and the process tree says whose they are.
func SelfDiskIO ¶ added in v0.113.0
SelfDiskIO is the bytes this process has caused to be read from and written to storage since it started (read_bytes and write_bytes in /proc/self/io): real I/O, not reads the page cache answered.
Types ¶
type Proc ¶
type Proc struct {
PID int32
PPID int32
// Name is the OS's short name for the process (macOS truncates it to 16
// bytes); Label is better for showing a person.
Name string
// UID is the owner's user id, -1 where the table does not say (Windows).
UID int64
// StartMs is when the process started, unix ms, 0 when unknown. A pid
// with a different start is a different process.
StartMs int64
// contains filtered or unexported fields
}
Proc is one row of the process table.
type Sampler ¶
type Sampler struct {
// contains filtered or unexported fields
}
Sampler turns cumulative CPU time into a rate. It is not safe for concurrent use.
type Usage ¶
type Usage struct {
// CPUPct is percent of one core since the previous sample of the same
// process; Warm is false on the first sample, when there is nothing to
// compare with and CPUPct is 0.
CPUPct float64
Warm bool
// MemBytes is the process's own memory (ownMemory), not its RSS.
MemBytes uint64
}
Usage is one process's cost.