sys

package
v0.35.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 8 Imported by: 0

README

Sys Package (internal/sys)

Cross-platform process management utilities.

Overview

This package handles low-level OS-specific operations for process group management, signal handling, and process lifecycle control. It abstracts the differences between Unix (PGID-based) and Windows (taskkill-based) process termination strategies.

Primary Purpose

Ensure proper cleanup of CLI processes and their children, preventing zombie processes and resource leaks.

Usage

import "github.com/hrygo/hotplex/internal/sys"

// Kill process group (Unix: PGID, Windows: Job Object)
sys.KillProcessGroup(cmd, jobHandle)

// Check if process is alive
if sys.IsProcessAlive(process) {
    // ...
}

// Diagnostics
result := sys.CheckCliAvailable()
if result.Available {
    fmt.Printf("Claude version: %s\n", result.Version)
}

Platform Differences

Platform Kill Strategy
Unix/Linux kill(-pgid, SIGKILL)
Windows taskkill /F /T /PID

Files

File Purpose
doc.go Package documentation
proc_unix.go Unix process management (PGID-based)
proc_windows.go Windows process management (Job Object-based)
diagnostics.go CLI and database health checks
path.go Path utilities

Documentation

Overview

Package sys provides cross-platform process management utilities.

This package handles low-level OS-specific operations for process group management, signal handling, and process lifecycle control. It abstracts the differences between Unix (PGID-based) and Windows (taskkill-based) process termination strategies.

The primary purpose is to ensure proper cleanup of CLI processes and their children, preventing zombie processes and resource leaks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignProcessToJob added in v0.9.3

func AssignProcessToJob(jobHandle uintptr, process *os.Process) error

AssignProcessToJob is a no-op on Unix (only used on Windows).

func CheckDatabaseHealth added in v0.32.0

func CheckDatabaseHealth(dbPath string) (latencyMs int, ok bool)

CheckDatabaseHealth checks if a SQLite database is accessible and returns latency. It uses a 5-second timeout to avoid blocking.

func CloseJobHandle added in v0.9.3

func CloseJobHandle(jobHandle uintptr)

CloseJobHandle is a no-op on Unix (only used on Windows).

func ConfigDir added in v0.27.0

func ConfigDir() string

ConfigDir returns the platform-specific directory for configuration files (XDG_CONFIG_HOME).

func DataDir added in v0.27.0

func DataDir() string

DataDir returns the platform-specific directory for data files (XDG_DATA_HOME).

func ExpandPath added in v0.21.0

func ExpandPath(path string) string

ExpandPath expands the home directory tilde (~) and environment variables in a path.

func IsProcessAlive

func IsProcessAlive(process *os.Process) bool

IsProcessAlive checks if the process is still running using Signal(0) (Unix).

func KillProcessGroup

func KillProcessGroup(cmd *exec.Cmd, jobHandle uintptr)

KillProcessGroup terminates the entire process tree using the negative PID (Unix). The jobHandle parameter is ignored on Unix (only used on Windows).

func LogDir added in v0.27.0

func LogDir() string

LogDir returns the platform-specific directory for log files.

func SetupCmdSysProcAttr

func SetupCmdSysProcAttr(cmd *exec.Cmd) (uintptr, error)

SetupCmdSysProcAttr configures the command to run in its own process group (Unix). Returns zero handle (unused on Unix).

Types

type CheckCliResult added in v0.32.0

type CheckCliResult struct {
	Available bool
	Version   string
}

CheckCliResult holds the result of a CLI availability check.

func CheckCliAvailable added in v0.32.0

func CheckCliAvailable() CheckCliResult

CheckCliAvailable checks if the Claude Code CLI is available and returns its version. It uses a 5-second timeout to avoid blocking.

Jump to

Keyboard shortcuts

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