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

process

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package process implements agentx tool and hook command execution, including platform-specific process-tree cleanup. Commands execute caller-supplied scripts; this package is not a sandbox or an authorization boundary. Tree setup and Start must complete before concurrent cancellation; exec.Cmd still requires one waiter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BashCommand

func BashCommand(ctx context.Context, script string) *exec.Cmd

BashCommand is like ShellCommand but runs script with "bash -c" when bash is on PATH, falling back to "sh -c". On Windows it runs cmd.exe like ShellCommand.

func ExecCommand

func ExecCommand(ctx context.Context, name string, args ...string) *exec.Cmd

ExecCommand returns a command running name with args directly, without a shell. Like ShellCommand, cancelling ctx kills the command together with the processes it started.

func ShellCommand

func ShellCommand(ctx context.Context, script string) *exec.Cmd

ShellCommand returns a command that runs script with "sh -c", or "cmd /d /s /c" on Windows, where script is passed to cmd.exe verbatim and cmd.exe parses it as typed at its prompt, expanding %VAR% and honoring ^, &, |, < and >. Cancelling ctx kills the shell and every process it started, not only the shell.

Types

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

Tree runs a command so that it can be killed together with every process it starts. On Unix the command runs in a new process group. On Windows it is placed in a Job Object before it runs; if the job cannot be set up, Kill falls back to taskkill /T, which misses descendants whose parent already exited and cannot reach any descendant once the command was waited for.

A process group is addressed by the ID of the command's process, which the system may reuse once the command was waited for and the group is empty. Tree therefore kills the group at most once after the command was waited for; later calls of Kill and Close signal nothing.

func NewTree

func NewTree(cmd *exec.Cmd) *Tree

NewTree prepares cmd, which must not have been started. If cmd was created with exec.CommandContext, cancelling the context kills the tree. The command must be started with Tree.Start, not cmd.Start or cmd.Run.

func (*Tree) Close

func (t *Tree) Close() error

Close kills what is left of the tree and releases its resources. Like Kill, it signals nothing once the tree was killed after the command was waited for.

func (*Tree) Kill

func (t *Tree) Kill() error

Kill kills the command and its descendants. It may be called at any time after Start. Once the command was waited for, the first call kills the descendants that outlived it; a caller that waits with cmd.Wait instead of Tree.Wait should call Kill right after it returns. Later calls, and calls after Close, signal nothing and return os.ErrProcessDone. Kill also returns os.ErrProcessDone when it finds nothing left to kill.

func (*Tree) Start

func (t *Tree) Start() error

Start starts the command. As with exec.Cmd.Start, the caller must wait for the command once Start succeeds, preferably with Tree.Wait.

func (*Tree) Wait

func (t *Tree) Wait() error

Wait waits for the command like cmd.Wait and then kills the processes it left behind.

Jump to

Keyboard shortcuts

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