process

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package process holds process management code for direct interaction with processes

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Process

type Process struct {
	Stderr     io.Reader
	Stdout     io.Reader
	Stdin      io.WriteCloser
	StdinMutex sync.Mutex
	DoneChan   chan bool
	// contains filtered or unexported fields
}

Process is a representation of a command to be run and access to its stdin/out/err

func NewProcess

func NewProcess(cmd string, args []string, workingDir string, logger *log.Logger, env []string, copySystemEnv bool) (*Process, error)

NewProcess returns a ready to use process object with the given options. If any errors occur during creation and setup, they are returned

func (*Process) GetReturnCode

func (p *Process) GetReturnCode() int

GetReturnCode returns the exit code of the process as an int. Calling this on a Process that has not been started will panic

func (*Process) GetReturnStatus

func (p *Process) GetReturnStatus() string

GetReturnStatus returns a string containing the return status of the process, an example would be "exit code 1"

func (*Process) GetStatus

func (p *Process) GetStatus() string

GetStatus returns the current status of the process, including memory and CPU usage

func (*Process) IsRunning

func (p *Process) IsRunning() bool

IsRunning returns whether or not the current process is running

func (*Process) Kill

func (p *Process) Kill() error

Kill sends SIGKILL to the process if it is running

func (*Process) Reset

func (p *Process) Reset() error

Reset cleans up an already-run process, making it ready to be run again

func (*Process) SendSignal

func (p *Process) SendSignal(sig os.Signal) error

SendSignal sends the given signal to the underlying process

func (*Process) Start

func (p *Process) Start() error

Start starts the process, if startup errors, that error is returned

func (*Process) Stop

func (p *Process) Stop() error

Stop sends SIGTERM to the process if it is running

func (*Process) StopOrKillTimeout

func (p *Process) StopOrKillTimeout(timeout time.Duration) error

StopOrKillTimeout asks the process to stop and waits for the configured timeout, after which it kills the process

func (*Process) UpdateCmd

func (p *Process) UpdateCmd(command string, args []string, workingDir string, env []string, copySystemEnv bool)

UpdateCmd sets the command and arguments to be used when creating the exec.Cmd used internally. It is safe for concurrent use. Note that this will only take effect on the next reset of the Process object

func (*Process) WaitForCompletion

func (p *Process) WaitForCompletion() error

WaitForCompletion blocks until the Process's command has completed. If an error occurs while waiting, it is returned

func (*Process) Write

func (p *Process) Write(data []byte) (int, error)

Write writes data to stdin on this process, adding a newline if one does not exist

func (*Process) WriteString

func (p *Process) WriteString(toWrite string) (int, error)

WriteString writes the given string to the stdin of the running process, If a newline does not end the given string. it is added

Jump to

Keyboard shortcuts

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