procout

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package procout starts a child process with its output read in a way that lets the process's exit be seen while a descendant still holds that output open.

exec.Cmd.StdoutPipe requires every read to finish before Wait is called, so a caller that reads to EOF first never sees the process exit while a descendant that inherited stdout or stderr is alive. Unreal Editor's detached UnrealTraceServer is one: it leaves the task's process group and outlives the editor. A service an OpenJD onEnter action starts in the background is another.

The child writes into OS pipes that procout itself reads, so exec's Wait returns at the exit. procout then waits for the output to close, or, once no process of the child's own group is left, for at most DrainDelay. After that the caller's readers end, but the pipes are still read and the output thrown away, so a process that holds them is never killed by SIGPIPE for writing.

It depends only on the standard library, so any sub-package of internal/worker can import it without creating a cycle.

Index

Constants

This section is empty.

Variables

View Source
var DrainDelay = 5 * time.Second

DrainDelay is how long output is still delivered after the process has exited and no process of its group is left, for a descendant that still holds it open. Output written after that is not delivered. A variable so tests can shorten it.

Functions

This section is empty.

Types

type Output

type Output struct {
	Stdout, Stderr io.Reader
	// contains filtered or unexported fields
}

Output is a started process's stdout and stderr.

func Start

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

Start starts cmd with its stdout and stderr connected to the returned Output's readers. The caller reads both, or calls Discard, and then calls Wait.

func (*Output) Abort

func (o *Output) Abort() error

Abort kills the process, drops its output and reaps it, for a caller that started the process but cannot go on with it. It returns the kill error; the process's exit status is of no interest after a forced kill.

func (*Output) Discard

func (o *Output) Discard()

Discard reads and drops both streams, for a caller that will not read them. It returns at once.

func (*Output) Exited

func (o *Output) Exited() <-chan struct{}

Exited returns a channel that is closed once Wait has seen the process exit, before Wait waits for the output to close. A caller that must not act on a process that has already exited, while its output is still being drained, selects on it. It is closed only by Wait, so it never closes for a caller that does not call Wait.

func (*Output) Wait

func (o *Output) Wait(groupAlive func() bool) (stillOpen bool, err error)

Wait waits for the process to exit, then for its output to close, and returns the process's exit error. groupAlive reports whether any process of the child's own group (its process group, or its job object on Windows) is still running; while one is, Wait keeps waiting, as it would for a child it had not detached from. Once none is, or when groupAlive is nil, the output is delivered for at most DrainDelay more. stillOpen reports that it had not closed by then, which means a process outside the group holds it; the caller's readers then reach EOF after what was delivered.

Jump to

Keyboard shortcuts

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