Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ProcessManager ¶
type ProcessManager struct { Procs map[int]*Subprocess // contains filtered or unexported fields }
ProcessManager manages multiple Subprocess objects
func NewProcessManager ¶
func NewProcessManager() *ProcessManager
NewProcessManager returns a pointer to a new ProcessManager struct
func (*ProcessManager) Fork ¶
func (p *ProcessManager) Fork(command string, args ...string) (*Subprocess, error)
Fork creates a new Subprocess but *does not* start it. At this point the process is not yet managed and needs to be started to become "managed"
func (*ProcessManager) Kill ¶
func (p *ProcessManager) Kill(pid int) error
Kill kills a subprocess with the given PID
func (*ProcessManager) KillAll ¶
func (p *ProcessManager) KillAll(sig ...os.Signal) []error
KillAll kills all subprocesses managed by the instance of ProcessManager
func (*ProcessManager) List ¶
func (p *ProcessManager) List() ([]*Subprocess, error)
List lists all subprocesses managed by the ProcessManager
type Subprocess ¶
type Subprocess struct { // PID of the subprocess PID int // Will return "true" if the process has exited Done bool // Return Code of the exited process RC int // Will return "true" if the return code is 0 (good exit) Success bool // Total lifetime of the process in miliseconds Duration time.Duration // ms // Time that the process was started StartTime time.Time // Time at the process was stopped StopTime time.Time // Any data written to *Subprocess.Stdin *before* *Subprocess.Start() is called // will be written to the process' stdin immediately after startup. // Data is treated as newline (\n) delimited. Stdin *bytes.Buffer // A buffer containing all of the output from the process' stdout Stdout *bytes.Buffer // A buffer containing all of the output from the process' stderr Stderr *bytes.Buffer // A channel on which any non-process errors will be sent // This is useful for logging errors without having to do dynamic // logging configuration or some other messy system Errors chan error // The command to be run Command string // Any arguments to be supplied to the command Args []string // Additional environment variables to be supplied to the process // in addition to those returned by os.Environ() Env map[string]string // Current working directory of the process CWD string // Process restart policy RestartPolicy string // always, on-failure, never // Slice of the files the process is holding open OpenFiles []File // PIDs of any child processes Children []int32 // User ID of the user that spawned the subprocess UID int // Rudimentary metrics for CPU, Memory, and thread count Metrics Metrics // contains filtered or unexported fields }
Subprocess contains all the methods and properties to manage a subprocess.
func (*Subprocess) Restart ¶
func (s *Subprocess) Restart() (int, error)
Restart calls Stop() and Start() in sequence
func (*Subprocess) Signal ¶
func (s *Subprocess) Signal(signal os.Signal) error
Signal allows a user to send a specific signal to the subprocess
func (*Subprocess) Start ¶
func (s *Subprocess) Start() (int, error)
Start starts the subprocess and populates struct fields