process_utils

package
v3.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProcessRunningCode = iota
	ProcessStoppedCode
	ProcessDeadCode
)
View Source
const TerminationTimeout = 35 * time.Second

TerminationTimeout is how long StopProcess and QuitProcess wait for the process to exit. A watchdog they stop kills its child 30 seconds after the stop signal and then reaps it and cleans up, so they wait longer than that.

Variables

View Source
var (
	ProcStateRunning = ProcessState{
		Code: ProcessRunningCode,

		Status: "RUNNING",
		PID:    0,
		// contains filtered or unexported fields
	}
	ProcStateStopped = ProcessState{
		Code: ProcessStoppedCode,

		Status: "NOT RUNNING",
		PID:    0,
		// contains filtered or unexported fields
	}
	ProcStateDead = ProcessState{
		Code: ProcessDeadCode,

		Status: "ERROR. The process is dead",
		PID:    0,
		// contains filtered or unexported fields
	}
)

Functions

func CheckPIDFile

func CheckPIDFile(pidFileName string) error

CheckPIDFile reports an error for a PID file that names a live process, or that cannot be read; a missing file, or one naming a dead process, is no error. It never removes a stale file: CreatePIDFile takes one over under the lock.

func CreatePIDFile

func CreatePIDFile(pidFileName string, pid int) (*pidfile.File, error)

CreatePIDFile takes the PID file over for pid and writes pid into it, as pidfile.Acquire does. The caller owns the file until it releases it, or keeps it when it exits while pid goes on.

func ExistsAndRecord

func ExistsAndRecord(pidFileName string) (bool, error)

ExistsAndRecord checks if the process with the given pidFileName exists and is alive. If it does, returns true, otherwise returns false. If something went wrong while trying to read the PID file, returns an error.

func GetPIDFromFile

func GetPIDFromFile(pidFileName string) (int, error)

GetPIDFromFile returns PID from the PIDFile.

func Interrupt

func Interrupt(pid int) error

Interrupt sends SIGINT to the process pid without waiting for it to exit. The caller tells that pid is the process it means: a pid read from a pid file may name another process by now.

func InterruptProcess

func InterruptProcess(pidFile string) (int, error)

InterruptProcess sends SIGINT to the process by pidFile without waiting for it to exit.

func IsProcessAlive

func IsProcessAlive(pid int) (bool, error)

IsProcessAlive checks if the process is alive.

func KillProcessGroup

func KillProcessGroup(pid int) error

KillProcessGroup kills the process group of the process pid with SIGKILL. The caller tells that pid is the process it means, as for Interrupt.

func QuitProcess

func QuitProcess(pid int) error

QuitProcess sends SIGQUIT to the process pid and waits TerminationTimeout for it to exit. The caller tells that pid is the process it means, as for Interrupt.

func StopProcess

func StopProcess(pidFile string) (int, error)

StopProcess stops the process by pidFile, waiting TerminationTimeout for it to exit.

func StopProcessWithin

func StopProcessWithin(pidFile string, timeout time.Duration) (int, error)

StopProcessWithin sends SIGINT to the process by pidFile and waits up to timeout for it to exit.

func WaitProcessTermination

func WaitProcessTermination(pid int, timeout time.Duration) error

WaitProcessTermination waits up to timeout for the process to exit.

Types

type ProcessState

type ProcessState struct {
	Code int

	Status string
	PID    int
	// contains filtered or unexported fields
}

func ProcessStatus

func ProcessStatus(pidFile string) ProcessState

ProcessStatus returns the status of the process.

func (ProcessState) FormattedStatus

func (procState ProcessState) FormattedStatus() string

FormattedStatus returns the status string formatted with the appropriate color.

func (ProcessState) String

func (procState ProcessState) String() string

String makes a string from ProcessState.

Jump to

Keyboard shortcuts

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