process

package
v0.0.0-...-dc64ae7 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Overview

Package process provides utilities for managing the current system process.

Index

Constants

This section is empty.

Variables

View Source
var OSExit = os.Exit

OSExit is the function used to terminate the current process. It defaults to os.Exit, but can be overridden for testing purposes.

Functions

func Crash

func Crash()

Crash will terminate the process with a panic that will generate stacktraces for all user-generated goroutines.

func CreatePIDFile

func CreatePIDFile(path string) error

CreatePIDFile writes the current process ID to a new file at the given path. The written file is removed when Exit is called, or when the process receives an os.Interrupt or SIGTERM signal.

func DisableAutoExit

func DisableAutoExit()

DisableAutoExit will prevent the process from automatically exiting after processing os.Interrupt or SIGTERM signals. This will not be enforced if Exit is called directly.

func Exit

func Exit(code int)

Exit runs the registered exit handlers, as if the os.Interrupt signal had been sent, and then terminates the process with the given status code. Exit blocks until the process terminates if it has already been called elsewhere.

func Init

func Init(directory string, name string) error

Init tries to acquire a process lock and write the PID file for the current process.

func Lock

func Lock(directory string, name string) error

Lock tries to acquire a process lock in the given directory. The acquired lock file is released when Exit is called, or when the process receives an os.Interrupt or SIGTERM signal.

This function has only been tested for correctness on Unix systems with filesystems where link is atomic. It may not work as expected on NFS mounts or on platforms like Windows.

func ReapOrphans

func ReapOrphans() bool

ReapOrphans reaps orphaned child processes and returns whether there are any unterminated child processes that are still active.

This is currently a no-op on all platforms except Linux.

func ResetHandlers

func ResetHandlers()

ResetHandlers drops all currently registered handlers.

func RunReaper

func RunReaper(ctx context.Context)

RunReaper continuously attempts to reap orphaned child processes until the given context is cancelled.

On Linux, this will register the current process as a child subreaper, and attempt to reap child processes whenever SIGCHLD is received. On all other platforms, this is currently a no-op.

func SetExitHandler

func SetExitHandler(handler func())

SetExitHandler registers the given handler function to run when receiving os.Interrupt or SIGTERM signals. Registered handlers are executed in reverse order of when they were set.

func SetSignalHandler

func SetSignalHandler(signal os.Signal, handler func())

SetSignalHandler registers the given handler function to run when receiving the specified signal. Registered handlers are executed in reverse order of when they were set.

Types

This section is empty.

Jump to

Keyboard shortcuts

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