Documentation
¶
Overview ¶
Package proctree kills a command's whole process tree: a process group on Unix, a job object (KILL_ON_JOB_CLOSE) on Windows, where the shell starts suspended and is resumed only after joining the job. Call New before Start, Started right after Start (it ends a shell that could not join), Kill to end the tree, Close once the command has exited (it also ends children left running in the background).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Limits ¶
type Limits struct {
// MemoryBytes caps the memory of one process and of the whole tree
// (Windows: ProcessMemoryLimit and JobMemoryLimit; Unix: RLIMIT_DATA).
MemoryBytes uint64
// Processes caps how many processes the tree may have at once (Windows:
// ActiveProcessLimit; Unix: RLIMIT_NPROC, which counts the whole user).
Processes int
// CPUTime caps the CPU time one process may use (Windows:
// PerProcessUserTimeLimit; Unix: RLIMIT_CPU).
CPUTime time.Duration
}
Limits caps what a command's process tree may use (tools.shell_limits). The zero value keeps every limit off. Windows enforces all three fields on the tree's job object; Unix sets them with setrlimit before the shell starts (memory and CPU time per process, the process count per user - a limitation of RLIMIT_NPROC the documentation spells out). A field the platform cannot enforce is ignored rather than approximated.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is the command's process group: the shell starts a new group, so killing -pid reaches every child it spawned.
func NewLimited ¶
NewLimited is New with a resource cap on the tree: the limits are set with setrlimit in a short sh wrapper before the shell itself starts, so the whole tree inherits them. A limit that cannot be set here (a shell without that ulimit flag) leaves that one limit off instead of failing the command.
func (*Tree) Close ¶
func (p *Tree) Close()
Close kills children the command left running in the background.