subprocess

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Local subprocess implementation using os/exec, process-tree termination, environment scrubbing, and spills.

Unix process groups, exit-signal collection, and group signaling.

Package subprocess implements the M36 subprocess interface, matching subprocess and subprocess-local. Specs explicitly describe argv, cwd, stdio, grace, and env. Spawn removes inherited OMNIX_* variables, then merges explicit environment entries; empty-value tombstones remove ordinary inherited variables too. CollectedOutput retains the tail beyond memory limits and may spill the full stream. Terminate acts on the process tree: taskkill /T on Windows, or SIGTERM, a grace period, then SIGKILL on Unix.

Index

Constants

View Source
const OmnixEnvPrefix = "OMNIX_"

OmnixEnvPrefix identifies managed environment variables removed before explicit overrides.

Variables

This section is empty.

Functions

func ScrubParentEnv

func ScrubParentEnv() []string

ScrubParentEnv removes OMNIX_* variables while preserving other environment entries.

Types

type CollectedOutput

type CollectedOutput struct {
	// Text contains the collected stream tail when truncated.
	Text string `json:"text"`
	// Truncated reports whether bytes were discarded from Text.
	Truncated bool `json:"truncated"`
	// SpillPath points to the full stream when truncation and spilling are available.
	SpillPath string `json:"spillPath,omitempty"`
}

CollectedOutput contains captured text and recovery information.

type LocalRuntime

type LocalRuntime struct{}

LocalRuntime executes local subprocesses through os/exec.

func NewLocal

func NewLocal() *LocalRuntime

NewLocal creates a local runtime.

func (*LocalRuntime) Spawn

Spawn starts a managed subprocess and immediately returns a handle.

type SubprocessCollect

type SubprocessCollect struct {
	// MaxBytes limits memory; overflow retains the tail.
	MaxBytes int
	// SpillMaxBytes limits full-stream storage; nonpositive disables spilling.
	SpillMaxBytes int
}

SubprocessCollect configures bounded in-memory collection and optional full-stream spilling.

type SubprocessHandle

type SubprocessHandle struct {
	// Pid identifies the process-tree root.
	Pid int
	// contains filtered or unexported fields
}

SubprocessHandle represents a live process and its descendant tree.

func (*SubprocessHandle) Collected

func (h *SubprocessHandle) Collected() *collectedOutputs

Collected returns output readers that remain usable after exit.

func (*SubprocessHandle) Done

func (h *SubprocessHandle) Done() <-chan SubprocessOutcome

Done returns process exit facts when it closes.

func (*SubprocessHandle) Terminate

func (h *SubprocessHandle) Terminate()

Terminate escalates SIGTERM through grace to SIGKILL for the tree; Windows forces termination immediately. It is idempotent and does nothing after the tree exits.

type SubprocessOutcome

type SubprocessOutcome struct {
	// ExitCode is -1 when a signal terminates the process.
	ExitCode int
	// Signal names the terminating signal, such as SIGTERM; empty on normal exit.
	Signal string
}

SubprocessOutcome records exit facts; callers classify their own timeout/cancellation signals.

type SubprocessSpawnSpec

type SubprocessSpawnSpec struct {
	// Argv contains executable argv[0] and arguments without shell interpretation.
	Argv []string
	// Cwd is the child working directory.
	Cwd string
	// StdoutMaxBytes and StderrMaxBytes default to 64 KB when nonpositive.
	StdoutMaxBytes int
	StderrMaxBytes int
	// SpillRoot is the complete-stream spill directory; empty disables spilling.
	SpillRoot string
	// GraceMs is the SIGTERM-to-SIGKILL grace period in milliseconds.
	GraceMs int
	// Env overlays explicit entries on the scrubbed parent environment.
	Env map[string]string
	// StdinData optionally supplies input and closes stdin when nonempty.
	StdinData string
}

SubprocessSpawnSpec explicitly describes a spawn request.

type SubprocessStdinMode

type SubprocessStdinMode string

SubprocessStdinMode selects ignored stdin or a piped stream.

const (
	StdinIgnore SubprocessStdinMode = "ignore"
	StdinPipe   SubprocessStdinMode = "pipe"
	// StdinData writes bytes then closes stdin for batch execution.
	StdinData = "data"
)

Jump to

Keyboard shortcuts

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