reaper

package
v2.38.11 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: 8 Imported by: 1 module, 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 reaper contains logic for reaping subprocesses. It is specifically used in the agent to avoid the accumulation of zombie processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ForkReap

func ForkReap(opt ...Option) (int, error)

ForkReap spawns a goroutine that reaps children. In order to avoid complications with spawning `exec.Commands` in the same process that is reaping, we forkexec a child process. This prevents a race between the reaper and an exec.Command waiting for its process to complete. The provided 'pids' channel may be nil if the caller does not care about the reaped children PIDs.

Returns the child's exit code (using 128+signal for signal termination) and any error from Wait4.

func IsInitProcess

func IsInitProcess() bool

IsInitProcess returns true if the current process's PID is 1.

Types

type Option

type Option func(o *options)

func WithCatchSignals

func WithCatchSignals(sigs ...os.Signal) Option

WithCatchSignals sets the signals that are caught and forwarded to the child process. By default no signals are forwarded.

func WithExecArgs

func WithExecArgs(args ...string) Option

WithExecArgs specifies the exec arguments for the fork exec call. By default the same arguments as the parent are used as dictated by os.Args. Since ForkReap calls a fork-exec it is the responsibility of the caller to avoid fork-bombing oneself.

func WithLogger added in v2.29.6

func WithLogger(logger slog.Logger) Option

func WithPIDCallback

func WithPIDCallback(ch reap.PidCh) Option

WithPIDCallback sets the channel that reaped child process PIDs are pushed onto.

func WithReapLock added in v2.32.0

func WithReapLock(mu *sync.RWMutex) Option

WithReapLock sets a mutex shared between the reaper and Wait4. The reaper holds the write lock while reaping, and ForkReap holds the read lock during Wait4, preventing the reaper from stealing the child's exit status. This is only needed for tests with instant-exit children where the race window is large.

func WithReaperStop added in v2.32.0

func WithReaperStop(ch chan struct{}) Option

WithReaperStop sets a channel that, when closed, stops the reaper goroutine. Callers that invoke ForkReap more than once in the same process (e.g. tests) should use this to prevent goroutine accumulation.

func WithReaperStopped added in v2.32.0

func WithReaperStopped(ch chan struct{}) Option

WithReaperStopped sets a channel that is closed after the reaper goroutine has fully exited.

Jump to

Keyboard shortcuts

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