procutil

package
v0.3.0-beta.35 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package procutil provides shared process helpers for Compozy runtime components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alive

func Alive(pid int) bool

Alive reports whether a process with the given PID is running.

func ConfigureCommandProcessGroup

func ConfigureCommandProcessGroup(cmd *exec.Cmd)

ConfigureCommandProcessGroup starts the command in its own process group so callers can signal and observe the full descendant tree.

func ConfigureCommandSession

func ConfigureCommandSession(cmd *exec.Cmd)

ConfigureCommandSession starts the command in a new Unix session.

func ConfigureCommandTerminalSession

func ConfigureCommandTerminalSession(cmd *exec.Cmd)

ConfigureCommandTerminalSession starts the command in a new session with a controlling terminal.

func CurrentProcessNiceness

func CurrentProcessNiceness() (int, error)

CurrentProcessNiceness reports the niceness of the calling process.

func FilteredDaemonEnv

func FilteredDaemonEnv(base []string) []string

FilteredDaemonEnv returns process environment entries safe to pass to child processes.

func IsProcessMissingError

func IsProcessMissingError(err error) bool

IsProcessMissingError reports whether a signal failed because its target no longer exists.

func IsolatedDaemonEnv

func IsolatedDaemonEnv(base []string) []string

IsolatedDaemonEnv returns only the fixed operational environment allowlist needed to launch local subprocesses. It intentionally drops all non-allowlisted daemon variables, including provider CLI credentials.

func KillCommandProcessGroupAndWait

func KillCommandProcessGroupAndWait(cmd *exec.Cmd, timeout time.Duration) error

KillCommandProcessGroupAndWait forcefully terminates any remaining members of the command's process group, then waits for the group to disappear.

func KillProcessGroupIDAndWait

func KillProcessGroupIDAndWait(pgid int, timeout time.Duration) error

KillProcessGroupIDAndWait forcefully terminates any remaining members of a process group.

func MatchesObservedStartTime

func MatchesObservedStartTime(observed, startedAt time.Time) bool

MatchesObservedStartTime compares persisted and kernel timestamps with launcher skew tolerance.

func MatchesStartTime

func MatchesStartTime(pid int, startedAt time.Time) bool

MatchesStartTime reports whether pid currently belongs to a process whose observed start time matches the recorded value closely enough to account for launcher-vs-kernel timestamp skew.

func ProcessGroupNiceness

func ProcessGroupNiceness(pgid int) (int, error)

ProcessGroupNiceness reports the niceness of the least-niced member of the process group.

func RegisterCommandProcessGroup

func RegisterCommandProcessGroup(_ *exec.Cmd) error

RegisterCommandProcessGroup keeps Unix parity with Windows job registration.

func ResolveLoginShellPath

func ResolveLoginShellPath(
	ctx context.Context,
	environment []string,
	options LoginShellPathOptions,
) (string, error)

ResolveLoginShellPath returns the PATH produced by the operator's login shell.

func SensitiveEnvName

func SensitiveEnvName(name string) bool

SensitiveEnvName reports whether an environment variable name commonly carries credentials.

func SetProcessGroupNiceness

func SetProcessGroupNiceness(pgid int, niceness int) error

SetProcessGroupNiceness lowers the CPU scheduling priority of every process in the process group to at least niceness. Descendants forked afterward inherit the value. Unprivileged callers can only raise niceness, so a group already at or above niceness (for example under a niced daemon) is left unchanged instead of failing with a permission error.

func Signal

func Signal(pid int, sig syscall.Signal) error

Signal sends sig to the process with the given PID.

func SignalCommandProcessGroup

func SignalCommandProcessGroup(cmd *exec.Cmd, sig syscall.Signal) error

SignalCommandProcessGroup delivers sig to the command's process group.

func SignalProcessGroupID

func SignalProcessGroupID(pgid int, sig syscall.Signal) error

SignalProcessGroupID delivers sig to the process group identified by pgid.

func SignalProcessGroupIDStrict

func SignalProcessGroupIDStrict(pgid int, sig syscall.Signal) error

SignalProcessGroupIDStrict reports when no member remains to receive the signal.

func StartedAt

func StartedAt(pid int) (time.Time, error)

StartedAt reports the observed start time for pid using the host process table.

func VerifyProcessExit

func VerifyProcessExit(pid int, startedAt time.Time) (bool, error)

VerifyProcessExit checks whether the recorded process identity is gone. A reused PID proves the original process exited; a failed lookup does not.

func WaitForCommandProcessGroupExit

func WaitForCommandProcessGroupExit(cmd *exec.Cmd, timeout time.Duration) error

WaitForCommandProcessGroupExit blocks until the command's process group no longer exists, which ensures descendants are gone before returning.

func WaitForProcessGroupIDExit

func WaitForProcessGroupIDExit(pgid int, timeout time.Duration) error

WaitForProcessGroupIDExit blocks until the process group identified by pgid no longer exists.

func WatchParentExit

func WatchParentExit(ctx context.Context, poll time.Duration, onExit func())

WatchParentExit calls onExit once if this process is reparented because its original parent exited, then returns; it stops early when ctx is done. It lets a child self-terminate when its launcher dies abruptly (SIGKILL, test timeout, Ctrl-C) — Darwin has no Pdeathsig. On Windows the kill-on-close job object (RegisterCommandProcessGroup) handles this, so that build is a no-op.

Types

type DetachedLaunchRequest

type DetachedLaunchRequest struct {
	Binary  string
	Args    []string
	Sandbox []string
	LogPath string
}

DetachedLaunchRequest describes one detached process launch with log capture.

type DetachedProcess

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

DetachedProcess wraps a detached child process whose stderr/stdout were appended to a log file.

func SpawnDetachedLoggedProcess

func SpawnDetachedLoggedProcess(
	ctx context.Context,
	req DetachedLaunchRequest,
) (*DetachedProcess, error)

SpawnDetachedLoggedProcess launches one detached child process whose stdout/stderr are appended to req.LogPath.

func (*DetachedProcess) Done

func (p *DetachedProcess) Done() <-chan struct{}

Done closes after the detached child has been reaped.

func (*DetachedProcess) PID

func (p *DetachedProcess) PID() int

PID reports the launched process id.

func (*DetachedProcess) Terminate

func (p *DetachedProcess) Terminate() error

Terminate stops the detached child when it has not exited yet.

func (*DetachedProcess) Wait

func (p *DetachedProcess) Wait() error

Wait blocks until the detached process exits and attaches recent log output to failures.

type LoginShellPathOptions

type LoginShellPathOptions struct {
	Timeout        time.Duration
	MaxOutputBytes int
}

LoginShellPathOptions bounds login shell PATH resolution.

Jump to

Keyboard shortcuts

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