{"modulePath":"github.com/stacklok/toolhive","version":"v0.72.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package process\n\nPackage process provides low level operations on OS processes\n\n## Constants\n\n```go\nconst ToolHiveDetachedEnv = \"TOOLHIVE_DETACHED\"\n```\nToolHiveDetachedEnv is the environment variable used to indicate that the process is running in detached mode.\n\n```go\nconst ToolHiveDetachedValue = \"1\"\n```\nToolHiveDetachedValue is the expected value of ToolHiveDetachedEnv when set.\n\n## Functions\n\n```go\nfunc FindProcess(pid int) (bool, error)\n```\nFindProcess finds a process by its ID and checks if it's running. This function works on Unix systems (Linux and macOS).\n\n```go\nfunc IsDetached() bool\n```\nIsDetached checks if the process is running in detached mode.\n\n```go\nfunc IsToolHiveProxyForWorkload(pid int, workloadName string) (bool, error)\n```\nIsToolHiveProxyForWorkload 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).\n\nWhen workloadName is empty, only verifies it is a ToolHive process. When workloadName is non-empty, also verifies the process cmdline contains \" start \\\u003cworkloadName\u003e \" (the detached proxy runs \"thv start \\\u003cname\u003e --foreground\").\n\nVerification checks, in order:\n\n 1. TOOLHIVE\\_DETACHED=1 in process environment (most reliable)\n 2. \"thv\" in executable path or command line (fallback when env unavailable)\n 3. workloadName in cmdline (when provided, avoids killing another workload's proxy)\n\n```go\nfunc KillProcess(pid int) error\n```\nKillProcess kills a process by its ID\n\n```go\nfunc WaitForExit(ctx context.Context, pid int) error\n```\nWaitForExit 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.\n\n","path":"github.com/stacklok/toolhive/pkg/process","name":"process","synopsis":"Package process provides low level operations on OS processes","isRedistributable":true}
