proc

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package proc implements sandbox.Process — the live-stream handle a ProcessHost hands back — once, for ANY backend. A long-lived process looks the same to its driver whether it runs as a host child (local) or inside a container reached via `docker exec` (docker): bytes in on stdin, bytes out on stdout, stderr drained to a bounded tail, and a memoized way to wait for or force its exit. The only per-backend parts are HOW to wait for and HOW to kill the process, which the backend supplies as closures.

See ../../docs/specs/SESSION.md (slice 2) for the design and the os/exec stream-plumbing rationale (explicit os.Pipe, caller-owned ends).

Index

Constants

View Source
const DefaultStderrCap = 64 << 10

DefaultStderrCap is the bound on retained stderr: the last 64 KiB. Enough to hold a crash's final log lines without letting a chatty server's stderr grow unbounded in memory (P4).

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

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

Process is the shared sandbox.Process. Construct it with New; the backend owns only the wait/kill closures and the three stream ends.

func New

func New(stdin io.Writer, stdout, stderrSrc io.Reader, maxStderr int, waitFn, killFn func() error) *Process

New builds a Process over a started backend process. stdin/stdout are the live streams handed to the driver. stderrSrc is drained in the background into a bounded ring (last maxStderr bytes) and closed when it reaches EOF, so the process never stalls on a full stderr pipe. waitFn blocks until the process exits and returns its status; it is run ONCE in the background (so the process is always reaped, even if the driver never calls Wait) and its result memoized. killFn terminates the process; it is invoked at most once.

func (*Process) Done

func (p *Process) Done() <-chan struct{}

Done is closed once the process has exited and been reaped. It lets a caller (e.g. a ctx-cancel watcher in the backend) wait for natural death without parking a goroutine in Wait. Not part of sandbox.Process — an extra the backends use during wiring.

func (*Process) Kill

func (p *Process) Kill() error

Kill terminates the process via the backend's closure, exactly once.

func (*Process) StderrSnapshot

func (p *Process) StderrSnapshot() []byte

func (*Process) Stdin

func (p *Process) Stdin() io.Writer

func (*Process) Stdout

func (p *Process) Stdout() io.Reader

func (*Process) Wait

func (p *Process) Wait() error

Wait blocks until the background reaper has observed the exit, then returns its (memoized) result. Safe to call any number of times, from any goroutine.

Jump to

Keyboard shortcuts

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