Help us shape the future of Go! Take the 2026 Go Developer Survey

proctree

package
v0.19.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package proctree runs a shell command as the root of its own process tree, streams its output, and kills the whole tree on cancellation, timeout or a failed output callback. It is the one shell executor behind the bash tool and the harness Exec port.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Isolate

func Isolate(cmd *exec.Cmd)

Isolate starts cmd in a new session, so it leads a process group Kill can reach.

func Kill

func Kill(pid int) error

Kill kills the process group led by pid, which Isolate started; a group already gone is os.ErrProcessDone. It never signals pid alone: after the leader is reaped that pid may be reused.

func Run

func Run(ctx context.Context, command Command) (int, error)

Run runs command to completion and returns the shell's exit status, 128 plus the signal number when a signal ended it.

func SpawnErrorCode

func SpawnErrorCode(err error) string

SpawnErrorCode is the code Node reports for a failed spawn ("ENOENT"), or "".

Types

type Command

type Command struct {
	Script string
	Dir    string
	Env    []string
	// Timeout is in seconds; nil means none.
	Timeout *float64
	// Shell resolves the shell once the timeout and context are checked.
	Shell func() (Shell, error)
	// Started receives the pid of the shell, which leads the tree.
	Started func(pid int)
	// OnData receives each output chunk, one call at a time; an error kills
	// the tree and becomes the run's error.
	OnData func(stderr bool, chunk []byte) error
}

Command is one run of a shell script.

type Error

type Error struct {
	Kind Kind
	Err  error
}

Error is a failed run; its text is upstream's.

func (*Error) Error

func (err *Error) Error() string

func (*Error) Unwrap

func (err *Error) Unwrap() error

type Kind

type Kind int

Kind classifies a failed run.

const (
	Spawn Kind = iota
	Aborted
	Timeout
)

type Shell

type Shell struct {
	Path  string
	Args  []string
	Stdin bool
}

Shell is a resolved shell: Path run with Args and then the command, or with the command on stdin when Stdin is set (the legacy WSL bash).

func FindShell

func FindShell(custom string, getenv func(string) string) (Shell, error)

FindShell resolves upstream's bash: custom when it is set, else the platform default, reading ProgramFiles through getenv on win32.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL