process

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 9 Imported by: 9

README

go-processmanager

Updated version for 2024

  • Updated gopsutils to v4
    • bumps module target to golang 1.18+
  • Allows setting working directory
  • Breaking Change config.KillSignal is now an *int - avoids the need to parse at runtime. options.WithKillSignal will need to be updated.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLog

func NewLog(path string) *os.File

Create a new file for logging

func SetSubreaper

func SetSubreaper() error

SetSubreaper configures the calling process to be a subreaper. A subreaper fulfills the role of init(1) for its descendant processes. When a process becomes orphaned (its immediate parent terminates), it will be reparented to the nearest still living ancestor subreaper. This is useful in containerized environments to ensure proper cleanup of orphaned child processes.

func WithArgs

func WithArgs(s ...string) func(cfg *Config) error

func WithGracefulTimeout

func WithGracefulTimeout(d time.Duration) func(cfg *Config) error

WithGracefulTimeout sets the duration to wait after SIGTERM before SIGKILL

func WithKillProcessGroup

func WithKillProcessGroup(b bool) func(cfg *Config) error

WithKillProcessGroup enables or disables killing the entire process group

func WithKillSignal

func WithKillSignal(i int) func(cfg *Config) error

WithKillSignal sets the given signal while attemping to stop. Defaults to 9

func WithName

func WithName(s string) func(cfg *Config) error

func WithSTDIN

func WithSTDIN(f *os.File) func(cfg *Config) error

func WithStateDir

func WithStateDir(s string) func(cfg *Config) error

func WithTemporaryStateDir

func WithTemporaryStateDir() func(cfg *Config) error

func WithWorkDir

func WithWorkDir(s string) func(cfg *Config) error

Types

type Config

type Config struct {
	Name             string
	Args             []string
	Combined         bool
	StateDir         string
	KillSignal       *int
	Environment      []string
	Stdin            *os.File
	WorkDir          string
	GracefulTimeout  time.Duration // Time to wait after SIGTERM before SIGKILL
	KillProcessGroup bool          // Whether to kill entire process group (default true)
}

func DefaultConfig

func DefaultConfig() *Config

func (*Config) Apply

func (cfg *Config) Apply(opts ...Option) error

Apply applies the given options to the config, returning the first error encountered (if any).

type Option

type Option func(cfg *Config) error

func WithEnvironment

func WithEnvironment(s ...string) Option

type Process

type Process struct {
	PID string
	// contains filtered or unexported fields
}

func New

func New(p ...Option) *Process

New builds up a new process with options

func (*Process) ExitCode

func (p *Process) ExitCode() (string, error)

ExitCode returns the exitcode associated with the process

func (*Process) IsAlive

func (p *Process) IsAlive() bool

IsAlive checks if the process is running or not

func (*Process) Run

func (p *Process) Run() error

Run starts the process and returns any error

func (*Process) StateDir

func (p *Process) StateDir() string

StateDir returns the process state directory

func (*Process) StderrPath

func (p *Process) StderrPath() string

StderrPath returns the file where the stderr of the process is appended to

func (*Process) StdoutPath

func (p *Process) StdoutPath() string

StdoutPath returns the file where the stdout is appended to

func (*Process) Stop

func (p *Process) Stop() error

Stop stops the running process by sending KillSignal to the PID annotated in the pidfile

Jump to

Keyboard shortcuts

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