proc

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package proc provides primitives for managing process lifecycle and hygiene.

Its primary goal is to prevent "zombie" processes by ensuring that child processes spawned by the application are automatically terminated when the parent process exits (concept known as "death pact" or "process hygiene").

Mechanisms

  • Windows: Uses Job Objects with JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE.
  • Linux: Uses SysProcAttr.Pdeathsig with SIGKILL.
  • Others: Falls back to standard os/exec behavior (no guarantee of cleanup).

Usage

Replace exec.Cmd.Start() with proc.Start(cmd):

cmd := exec.Command("worker")
if err := proc.Start(cmd); err != nil {
    log.Fatal(err)
}

The child process is now linked to the parent's lifecycle.

Index

Constants

This section is empty.

Variables

View Source
var StrictMode bool

StrictMode if true, will cause Start to return an error on unsupported platforms instead of just logging a warning. Default is false.

Functions

func Start

func Start(cmd *exec.Cmd) error

Start starts the specified command but ensures that the child process is killed if the parent process (this process) dies.

On Linux, it uses SysProcAttr.Pdeathsig (SIGKILL). On Windows, it uses Job Objects (JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE).

On other platforms, it falls back to cmd.Start() and logs a warning, unless StrictMode is set to true, in which case it returns an error.

This is a safer alternative to cmd.Start() for long-running child processes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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