Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func KillPID ¶
KillPID sends SIGTERM to the process group for pid, waits up to gracefulTimeout seconds, then escalates to SIGKILL. On Windows it uses TerminateProcess.
func KillSessionJobObject ¶ added in v0.12.41
KillSessionJobObject is a no-op on non-Windows platforms. The session-wide process containment on Unix is implemented via POSIX process groups (see sessionpgid_unix.go's KillSessionPGID) so this stub exists only so cross-platform callers in internal/daemon can invoke the API unconditionally without build tags. The handle parameter is always zero on non-Windows (the client never reports a job handle when SessionJobHandle is unset) and this function returns nil immediately.
func KillSessionPGID ¶ added in v0.12.41
func KillSessionPGID(sessionPGID int, killSelfPID int, gracefulTimeout time.Duration, aggressive bool) error
KillSessionPGID sends SIGTERM to the POSIX process group identified by sessionPGID, waits up to gracefulTimeout for the group to drain, then escalates to SIGKILL. This is the session-shutdown equivalent of signalProcessGroup: it reaps every process that inherited the pgid from the PTY child session leader, including `npm run dev &` style jobs the coding agent spawned via non-interactive bash (which does not enable job control and therefore does not give backgrounded pipelines their own pgid).
aggressive selects SIGKILL immediately (used when the daemon is in aggressive-shutdown mode with a tight deadline, matching the existing ProcessManager.StopAll behavior).
killSelfPID is the caller's own PID. It is EXCLUDED from the kill so the daemon does not signal itself when it happens to share the pgid (it shouldn't, but defensive). Pass 0 to disable self-exclusion.
Returns an error only for the final verification step; best-effort EPERM and ESRCH during signal delivery are not reported since they are normal (the group may drain mid-loop).
func MembersOfPGID ¶ added in v0.12.41
MembersOfPGID returns the PIDs of every process currently in the given POSIX process group. Callers: session cleanup (to verify the pgid is empty after SIGKILL), orphan scanning (to find sessions whose leaders are gone but children still live), and tests.
On WSL2 the same /proc layout applies, so no special-casing is needed. On platforms without /proc this falls back to best-effort: Getpgid(pid) on every pid in Scan() output. Returns nil on error.
Types ¶
type OrphanPGID ¶ added in v0.12.41
type OrphanPGID struct {
PGID int // process group ID (= original session leader PID)
Members []int // live member PIDs currently in this pgid
}
OrphanPGID describes a POSIX process group whose session leader PID is no longer alive but whose members are still running, owned by the caller's euid, and not members of any of the exclude sets the caller provided.
Found by ScanOrphanedPGIDs. Consumed by daemon startup cleanup to reap sessions that leaked across a daemon restart (see Slice B of task O9QzO07vM8JB).
func ScanOrphanedPGIDs ¶ added in v0.12.41
func ScanOrphanedPGIDs(callerUID int, excludePGIDs map[int]bool) []OrphanPGID
ScanOrphanedPGIDs enumerates /proc and returns every pgid that qualifies as orphaned for the purpose of daemon-startup cleanup. A pgid is orphaned when ALL of the following are true:
- The pgid itself is > 1 (pid 0/1 are never treated as pgids).
- The pgid is NOT in excludePGIDs (typically: the caller's own pgid plus the pgid of the daemon process and any ancestor we don't want to kill).
- The leader PID (the process whose PID equals the pgid, i.e. the original session leader) does NOT currently exist. This is the "leader died, members reparented to init" case Slice B targets.
- At least one live process is still a member of the pgid.
- EVERY live member is owned by the caller's real uid. This is the safety barrier: if any member belongs to a different uid, we skip the entire pgid to avoid ever touching another user's processes. (root daemon, for example, must not reap a non-root user's pgids.)
callerUID is the uid that members must match. Pass syscall.Getuid() in production; tests pass an arbitrary value to exercise filtering paths.
Returns nil on /proc read error or when /proc is unavailable (non-Linux Unix). Callers that need absolute correctness on those platforms must layer their own fallback. On Linux and WSL2 /proc is always present.
type ProcInfo ¶
type ProcInfo struct {
PID int
PPID int // parent PID (0 if unavailable)
Command string // basename of the executable
Cmdline string // full command line
Cwd string // working directory (may be empty on some platforms)
}
ProcInfo describes a running process discovered via OS-level scanning.
func ScanWindows ¶
ScanWindows returns Windows-side processes when running under WSL. On non-WSL Unix this returns nil.