process

package
v0.11.1 Latest Latest
Warning

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

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

Documentation

Overview

Package process provides low level operations on OS processes

Index

Constants

View Source
const ToolHiveDetachedEnv = "TOOLHIVE_DETACHED"

ToolHiveDetachedEnv is the environment variable used to indicate that the process is running in detached mode.

View Source
const ToolHiveDetachedValue = "1"

ToolHiveDetachedValue is the expected value of ToolHiveDetachedEnv when set.

Variables

This section is empty.

Functions

func FindProcess

func FindProcess(pid int) (bool, error)

FindProcess finds a process by its ID and checks if it's running. This function works on Unix systems (Linux and macOS).

func IsDetached added in v0.0.33

func IsDetached() bool

IsDetached checks if the process is running in detached mode.

func IsToolHiveProxyForWorkload added in v0.11.1

func IsToolHiveProxyForWorkload(pid int, workloadName string) (bool, error)

IsToolHiveProxyForWorkload returns true if the given PID belongs to the ToolHive proxy for the specified workload, so it is safe to kill when freeing a port. Returns false if the process is not that workload's proxy or if identity cannot be verified (fail-safe: do not kill).

When workloadName is empty, only verifies it is a ToolHive process. When workloadName is non-empty, also verifies the process cmdline contains " start <workloadName> " (the detached proxy runs "thv start <name> --foreground").

Verification checks, in order:

  1. TOOLHIVE_DETACHED=1 in process environment (most reliable)
  2. "thv" in executable path or command line (fallback when env unavailable)
  3. workloadName in cmdline (when provided, avoids killing another workload's proxy)

func KillProcess

func KillProcess(pid int) error

KillProcess kills a process by its ID

func WaitForExit added in v0.11.1

func WaitForExit(ctx context.Context, pid int) error

WaitForExit waits for the process with the given PID to exit. It polls FindProcess every 50ms until the process is no longer running or the context is cancelled. Callers should use context.WithTimeout to impose a deadline. Returns nil when the process has exited, or an error on context cancellation.

Types

This section is empty.

Jump to

Keyboard shortcuts

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