Documentation ¶
Overview ¶
Package process provides utilities for managing the current system process.
Index ¶
- Variables
- func Crash()
- func CreatePIDFile(path string) error
- func DisableAutoExit()
- func Exit(code int)
- func Init(directory string, name string) error
- func Lock(directory string, name string) error
- func ReapOrphans() bool
- func ResetHandlers()
- func RunReaper(ctx context.Context)
- func SetExitHandler(handler func())
- func SetSignalHandler(signal os.Signal, handler func())
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 Lock ¶
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 RunReaper ¶
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 ¶
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.