background

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 17 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigureChildProcessGroup

func ConfigureChildProcessGroup(cmd *exec.Cmd)

ConfigureChildProcessGroup puts a child into its own process group so the whole group can be signalled as a unit. terminateProcess depends on this: it signals the negative PID (the group), so any process the child forks dies with it instead of being orphaned. Must be called before cmd.Start.

func DefaultRoot

func DefaultRoot(env map[string]string) string

func TerminateCommand

func TerminateCommand(cmd *exec.Cmd) error

TerminateCommand stops a started command and reaps its leader. The caller must have exclusive ownership of cmd: it must not have previously called Wait or Process.Release, and no goroutine may call either concurrently. On POSIX it stops the whole group when the command was configured as its leader; ordinary commands safely fall back to PID/tree discovery. When POSIX observes a waitable-zombie leader before signalling, a termination error is discarded after reap only if the launch-time signal target is independently gone; the leader observation alone says nothing about descendants. Windows retains its existing behavior of ignoring the expected kill-attempt error when GetExitCodeProcess shows that the root was already dead. Windows cannot rediscover a tree from a dead root, so descendants may survive there. `zero daemon start` needs this operation when readiness times out: it launched the child, so it must both stop the tree and collect the leader.

The order matters: the tree is signalled first, because Wait releases the leader's PID and a later group lookup could then resolve to nothing (or, worse, to a recycled PID). Termination stays in the shared execution lifecycle primitives rather than introducing a second platform-specific killer.

If the bounded reap times out, the Wait call already started by this function continues in its goroutine. From that point onward the caller must not access cmd at all, including ProcessState, because that would race with Wait.

func TerminateCommandGroup

func TerminateCommandGroup(cmd *exec.Cmd) error

TerminateCommandGroup stops a started command's process group on POSIX, or its process tree on Windows, WITHOUT reaping it.

It is TerminateCommand without the Wait, for a caller whose Wait already runs somewhere else: a worker pool waiting on the command in its own goroutine, or the command's own Cancel hook, which exec.Cmd invokes while its Wait is in progress. TerminateCommand would be a second Wait there. Both used to pass cmd.Process.Pid to TerminateProcess, which rediscovers the group at signal time with Getpgid, and once the leader has exited that lookup fails, so only the dead leader was signalled and its descendants kept running. When cmd was configured by ConfigureChildProcessGroup the group now comes from that launch-time configuration instead. On Windows it is the tree kill TerminateProcess performs, with the process handle pinned while it runs so the PID cannot be recycled underneath it; once the command has been waited that pin fails with an error wrapping os.ErrProcessDone.

func TerminateProcess

func TerminateProcess(pid int) error

TerminateProcess stops a background process by PID — on Windows its process tree; on POSIX its whole process group when the PID leads its own group (the invariant ConfigureChildProcessGroup establishes for processes started through this package), otherwise just the individual PID. The PID-only fallback is deliberate — signalling a non-leader's group could hit unrelated processes — but it means descendants of a non-leader are NOT reaped; pass a group leader to guarantee group termination. Exported for callers that hold a raw PID and cannot route through the manager, e.g. cleaning up a just-launched child whose PID could not be recorded.

Types

type Manager

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

func NewManager

func NewManager(rootDir string) (*Manager, error)

func NewManagerWithOptions

func NewManagerWithOptions(options ManagerOptions) (*Manager, error)

func (*Manager) Get

func (manager *Manager) Get(taskID string) (Task, bool)

func (*Manager) Kill

func (manager *Manager) Kill(taskID string) error

func (*Manager) KillRunning

func (manager *Manager) KillRunning() error

func (*Manager) List

func (manager *Manager) List() []Task

func (*Manager) ListByParent

func (manager *Manager) ListByParent(parentID string) []Task

func (*Manager) LoadWarnings

func (manager *Manager) LoadWarnings() []string

func (*Manager) MarkExited

func (manager *Manager) MarkExited(taskID string, status Status, exitCode int) error

func (*Manager) OutputPath

func (manager *Manager) OutputPath(taskID string) string

func (*Manager) Register

func (manager *Manager) Register(input RegisterInput) (string, error)

func (*Manager) RootDir

func (manager *Manager) RootDir() string

func (*Manager) SetPID

func (manager *Manager) SetPID(taskID string, pid int) error

func (*Manager) UpdateStatus

func (manager *Manager) UpdateStatus(taskID string, status Status, exitCode int) error

type ManagerOptions

type ManagerOptions struct {
	RootDir     string
	Env         map[string]string
	Now         func() time.Time
	KillProcess func(pid int) error
}

type RegisterInput

type RegisterInput struct {
	TaskID         string
	Type           string
	SpecialistName string
	Description    string
	ParentID       string
	PID            int
	OutputFile     string
}

type Status

type Status string
const (
	StatusRunning   Status = "running"
	StatusCompleted Status = "completed"
	StatusError     Status = "error"
	StatusKilled    Status = "killed"
)

type Task

type Task struct {
	ID             string    `json:"id"`
	Type           string    `json:"type"`
	SpecialistName string    `json:"specialistName,omitempty"`
	Description    string    `json:"description,omitempty"`
	ParentID       string    `json:"parentId,omitempty"`
	PID            int       `json:"pid,omitempty"`
	Status         Status    `json:"status"`
	OutputFile     string    `json:"outputFile"`
	StartedAt      time.Time `json:"startedAt"`
	CompletedAt    time.Time `json:"completedAt,omitempty"`
	ExitCode       int       `json:"exitCode,omitempty"`
}

Jump to

Keyboard shortcuts

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