Documentation
¶
Overview ¶
Package process runs external commands together with the processes that they start, and limits the memory of these process trees.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AvailableMemory ¶
AvailableMemory returns the memory in bytes that new processes can use: MemAvailable of the system, reduced to the headroom of each cgroup v2 memory limit of the current process and its ancestors.
func Run ¶
Run starts cmd with the processes that it starts in one process tree and waits for cmd to complete. When the context of cmd is done, Run stops the complete tree. After cmd exits, Run stops any process that remains in the tree. On Unix the tree is a new process group. On Windows it is a new job object, and cmd starts suspended until it is in the job.
Run waits at most five seconds for output pipes after cmd exits or its context is done, so a descendant that holds a pipe open cannot block it.
cmd must come from exec.CommandContext. Run sets cmd.SysProcAttr, cmd.Cancel, and cmd.WaitDelay. It returns the error of cmd.Run, joined with any error of the tree control.
Types ¶
type Usage ¶
type Usage struct {
// Peak is the peak memory in bytes of the largest process in the tree:
// the resident set on Unix, and the committed memory on Windows.
Peak uint64
// OverLimit is true when the tree used more memory than its limit, so
// RunBounded stopped it.
OverLimit bool
}
Usage is the memory use of a process tree that RunBounded ran.
func RunBounded ¶
RunBounded runs cmd like Run and returns the memory use of the tree. When memoryLimit is not zero, a watchdog samples the total memory of the tree every sampleInterval: the resident memory of its processes on Unix, and the peak committed memory of the job on Windows. When the total passes memoryLimit, the watchdog stops the tree and Usage.OverLimit is true. When the watchdog cannot read the memory of a running tree, it stops the tree and RunBounded returns the error.