process

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2025 License: MIT Imports: 10 Imported by: 1

Documentation

Overview

Package process Provide some process handle util functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(pid int) bool

Exists check process running by given pid

func ExistsByName added in v0.6.18

func ExistsByName(name string, fuzzyMatch bool) bool

ExistsByName check process running by given name

func Kill added in v0.6.2

func Kill(pid int, signal syscall.Signal) error

Kill a process by pid

func KillByName added in v0.6.2

func KillByName(keywords string, sig syscall.Signal) error

KillByName kill process by name match

func PID added in v0.3.6

func PID() int

PID get current process ID

func PIDByName added in v0.6.2

func PIDByName(keywords string) int

PIDByName get PID by process name match(by pgrep)

func ProcInfo added in v0.6.2

func ProcInfo(pid int) (*os.Process, error)

ProcInfo looks for a running process by its pid.

alias of os.FindProcess()

func Start added in v0.6.2

func Start(name string, argv []string, attr *os.ProcAttr) (*os.Process, error)

Start starts a new process with the program, arguments and attributes specified by name, argv and attr.

alias of os.StartProcess()

func StopByName added in v0.6.18

func StopByName(name string, option ...*StopProcessOption) (bool, string, error)

StopByName Stop process based on process name.

return (exists, output, error). check error to see if the process exists

Usage:

StopByName("MyApp.exe")

Types

type PidFile added in v0.5.6

type PidFile struct {
	// contains filtered or unexported fields
}

PidFile struct

func NewPidFile added in v0.5.6

func NewPidFile(file string) *PidFile

NewPidFile instance

func (*PidFile) Exists added in v0.5.6

func (pf *PidFile) Exists() bool

Exists of th pid file

func (*PidFile) File added in v0.5.6

func (pf *PidFile) File() string

File path

func (*PidFile) PID added in v0.5.6

func (pf *PidFile) PID() int

PID value

func (*PidFile) Save added in v0.5.6

func (pf *PidFile) Save() error

Save PID value to file

func (*PidFile) SetPID added in v0.5.6

func (pf *PidFile) SetPID(val int) int

SetPID value

func (*PidFile) String added in v0.5.6

func (pf *PidFile) String() string

String PID value string

type StopProcessOption added in v0.6.18

type StopProcessOption struct {
	// Check if the process exists before stopping it
	CheckExist bool
	// Whether to force exit the process
	ForceKill bool
	// Whether to wait for the process to exit
	WaitExit bool
	// How long to wait for the process to exit
	ExitTimeout int
	// Signal to send to the process(non-win)
	Signal syscall.Signal
}

StopProcessOption stop process option

Jump to

Keyboard shortcuts

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