Skip to content
/ procio Public

Lightweight, standalone Go module for robust process lifecycle management and interactive I/O.

License

Notifications You must be signed in to change notification settings

aretw0/procio

Repository files navigation

procio

Go Report Card Go Reference License Release

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.

Installation

go get github.com/aretw0/procio

Usage

starting a process safely

import "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)

Reading Input Robustly

import "github.com/aretw0/procio/scan"

scanner := scan.NewScanner(os.Stdin)
scanner.Start(ctx) // Handles transient interrupts

Enabling TTY Cancellation

For 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 EOF

Observability

procio is opinionated about specific mechanisms but unopinionated about logging/metrics. You can inject your own observer:

import "github.com/aretw0/procio"

procio.SetObserver(myObserver)