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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.