pidhandle

package
v5.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package for handling processes and PIDs.

Package for handling processes and PIDs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PIDHandle

type PIDHandle interface {
	// Returns the PID associated with this PIDHandle.
	PID() int
	// Releases the PIDHandle resources.
	Close() error
	// Sends the signal to process.
	Kill(signal unix.Signal) error
	// Returns true in case the process is still alive.
	IsAlive() (bool, error)
	// Returns a serialized representation of the PIDHandle.
	// This string can be passed to NewPIDHandleFromString to recreate
	// a PIDHandle that reliably refers to the same process as the original.
	String() (string, error)
}

PIDHandle defines an interface for working with operating system processes in a reliable way. OS-specific implementations include additional logic to try to ensure that operations (e.g., sending signals) are performed on the exact same process that was originally referenced when the PIDHandle was created via NewPIDHandle or NewPIDHandleFromString.

This prevents accidental interaction with a different process in scenarios where the original process has exited and its PID has been reused by the system for an unrelated process.

func NewPIDHandle

func NewPIDHandle(pid int) (PIDHandle, error)

Creates new PIDHandle for a given process pid.

Note that there still can be a race condition if the process terminates *before* the PIDHandle is created. It is a caller's responsibility to ensure that this either cannot happen or accept this risk.

func NewPIDHandleFromString

func NewPIDHandleFromString(pid int, pidData string) (PIDHandle, error)

Creates new PIDHandle for a given process pid using the pidData originally obtained from PIDHandle.String().

Jump to

Keyboard shortcuts

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