Documentation
¶
Overview ¶
Package proc spawns and reaps one child process with explicit pipes, group control, and a single Wait.
It is the only lifecycle mechanism for harness children. exec.CommandContext is deliberately not used: a canceled context must not orphan a child in the middle of a protocol write, and a vendor child needs a flush window before it is signalled.
Index ¶
- Constants
- func Alive(pid int) bool
- func ChildEnv(overrides map[string]string) []string
- func FirstLine(s string) string
- func KillGroup(pgid, pid int)
- func StartToken(pid int) string
- func TermSignal() os.Signal
- type Opts
- type Proc
- func (p *Proc) Argv() []string
- func (p *Proc) CloseStdin() error
- func (p *Proc) Done() <-chan struct{}
- func (p *Proc) ExitCode() int
- func (p *Proc) GracefulClose(timeout time.Duration) error
- func (p *Proc) KillTree() error
- func (p *Proc) PID() int
- func (p *Proc) Pgid() int
- func (p *Proc) SignalGroup(sig os.Signal)
- func (p *Proc) Stderr() string
- func (p *Proc) Stdin() io.Writer
- func (p *Proc) Stdout() io.Reader
- func (p *Proc) Wait(ctx context.Context) (int, error)
- func (p *Proc) WaitTimeout(d time.Duration) bool
Constants ¶
const GracefulCloseTimeout = 5 * time.Second
GracefulCloseTimeout is the default flush window between close-stdin, SIGTERM, and SIGKILL. The vendor SDK comment is load-bearing: SIGTERM too early can truncate the vendor session file and lose the last assistant message.
Variables ¶
This section is empty.
Functions ¶
func ChildEnv ¶
ChildEnv merges the process environment with overrides. Override keys win; an empty or reserved key is ignored. The result is in "K=V" form.
func KillGroup ¶
func KillGroup(pgid, pid int)
KillGroup SIGKILLs the process group, then the process. It works on a process this library did not spawn, which is what ledger reconcile needs.
func StartToken ¶
StartToken returns an identity token for a live pid: its start time. A mismatched token means the pid was reused and is not ours.
func TermSignal ¶
TermSignal is the graceful stop request this platform can deliver to a process group.
Types ¶
type Opts ¶
type Opts struct {
// Path is the executable. It must be a native binary on Windows; .cmd and
// .bat shims are refused.
Path string
Args []string
Dir string
// Env is the full child environment in "K=V" form. Nil inherits the
// parent environment.
Env []string
// OnStderr receives each stderr line as it is read. It is optional and
// runs on the drain goroutine, so it must not block.
OnStderr func(string)
}
Opts describes one child to spawn.
type Proc ¶
type Proc struct {
// contains filtered or unexported fields
}
Proc is a spawned child.
func Start ¶
Start spawns a child. The returned Proc has a bounded stderr tail reader attached; stdout is the caller's to frame.
func (*Proc) CloseStdin ¶
CloseStdin closes the write side of the child's stdin once.
func (*Proc) GracefulClose ¶
GracefulClose closes stdin, waits for the child to flush, then escalates SIGTERM and SIGKILL on the process group. timeout is per stage (default GracefulCloseTimeout).
func (*Proc) SignalGroup ¶
SignalGroup delivers sig to the whole process group when possible, else to the process.