ownedproc

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ownedproc runs a child process with exactly one owner of its wait.

A started process has two things a test needs: a way to signal it, and a way to learn that it exited. Splitting those between a body and a teardown path invites two waiters on one child, and concurrent waits can reap the wrong process once an id is reused (go.dev/issue/67642). One goroutine therefore owns the wait for a child's whole life; everything else observes completion through Done and signals through the retained process object.

Test-support only. It lives under internal/ and is imported solely by _test.go files; nothing here is part of the product surface.

Index

Constants

This section is empty.

Variables

View Source
var ErrStopTimeout = errors.New("owned child did not complete after being signalled")

ErrStopTimeout reports that a stopped child did not reach its wait owner's completion within the caller's bound.

Functions

This section is empty.

Types

type Child

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

Child is a started process whose wait has exactly one owner.

func Start

func Start(cmd *exec.Cmd) (*Child, error)

Start starts cmd and takes ownership of waiting on it. The caller owns teardown and must arrange for Stop to run.

func (*Child) AwaitExit

func (c *Child) AwaitExit(timeout time.Duration) (error, bool)

AwaitExit blocks until the wait owner completes, and reports whether it did so within the bound.

func (*Child) Done

func (c *Child) Done() <-chan struct{}

Done is closed once the sole wait has completed and the result is stored.

func (*Child) Err

func (c *Child) Err() error

Err returns the wait result. It is meaningful only after Done is closed.

func (*Child) KillCalls

func (c *Child) KillCalls() int64

KillCalls reports how many times teardown signalled the child.

func (*Child) PID

func (c *Child) PID() int

PID reports the child's process id, for diagnostics and for asking the operating system about it.

The retained process object is deliberately not exported. Handing it out would hand out a second way to wait on this child, which is the one thing the ownership rule exists to prevent; callers signal through Signal instead.

func (*Child) Signal

func (c *Child) Signal(sig os.Signal) error

Signal sends sig to the retained process.

func (*Child) Stop

func (c *Child) Stop(timeout time.Duration) error

Stop is teardown. A child that has already exited is left alone; otherwise the retained process is killed and Stop joins the existing wait owner. It never waits on the process itself, so there is never a second waiter.

func (*Child) WaitCalls

func (c *Child) WaitCalls() int64

WaitCalls reports how many times the sole wait ran. Any value but one means the ownership rule was broken.

Jump to

Keyboard shortcuts

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