procio is a lightweight, standalone set of composable primitives for safe process lifecycle and interactive I/O in Go.
It provides three core primitives:
- proc: Leak-free process management (ensures child processes die when parent dies).
- termio: Interruptible terminal I/O (handling interrupts and safe terminal handles).
- scan: Robust input scanning with protection against "Fake EOF" signals on Windows.
go get github.com/aretw0/procioimport "github.com/aretw0/procio/proc"
cmd := exec.Command("long-running-worker")
// Uses Pdeathsig (Linux) or Job Objects (Windows) to enforce cleanup
err := proc.Start(cmd)import "github.com/aretw0/procio/scan"
scanner := scan.NewScanner(os.Stdin)
scanner.Start(ctx) // Handles transient interruptsFor interactive CLIs that need Ctrl+C cancellation support:
import (
"context"
"github.com/aretw0/procio/scan"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
scanner := scan.NewScanner(os.Stdin,
scan.WithInterruptible(), // Enables context cancellation via Ctrl+C
scan.WithLineHandler(func(line string) {
fmt.Println("Got:", line)
}),
)
scanner.Start(ctx) // Returns when context is cancelled or EOFprocio is opinionated about specific mechanisms but unopinionated about logging/metrics.
You can inject your own observer:
import "github.com/aretw0/procio"
procio.SetObserver(myObserver)