process

package
v0.0.0-...-f783259 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MPL-2.0 Imports: 14 Imported by: 4

Documentation

Overview

this package provides functions to interact with the os processes You can list all the processes running on the os, filter them via a regexp and then use them from in other masche modules, because they are already open.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseAll

func CloseAll(ps []Process) (harderrors []error, softerrors []error)

CloseAll closes all the processes from the given slice.

func GetAllPids

func GetAllPids() (pids []int, harderror error, softerrors []error)

GetAllPids returns a slice with al the running processes' pids.

func ProcessExe

func ProcessExe(pid int) (string, error)

Types

type Process

type Process interface {
	// Pid returns the process' pid.
	Pid() int

	// Name returns the process' binary full path.
	Name() (name string, harderror error, softerrors []error)

	// Closes this Process.
	Close() (harderror error, softerrors []error)

	// Handle returns an opaque value which's meaning dependes on the OS-specific implementation of it.
	// It works like an interface{} that you must cast, but we are using a uintptr because we need to return C values,
	// and casting between them in different modules panics if you use interface{}.
	Handle() uintptr
}

Process type represents a running processes that can be used by other modules. In order to get a Process on of the Open* functions must be called, and once it's not needed it must be closed.

func GetProcess

func GetProcess(pid int) Process

func OpenAll

func OpenAll() (ps []Process, harderror error, softerrors []error)

OpenAll opens all the running processes returning a slice of Process. A race condition may make this generate some softerrors because from the time pids are get to actually opened some of them may have dead.

func OpenByName

func OpenByName(r *regexp.Regexp) (ps []Process, harderror error, softerrors []error)

OpenByName recieves a Regexp an returns a slice with all the Processes whose name matches it.

func OpenFromPid

func OpenFromPid(pid int) (p Process, harderror error, softerrors []error)

OpenFromPid opens a process by its pid.

type ProcessInfo

type ProcessInfo interface {
	GetId() int
	GetCommand() string
	GetParentProcessId() int
	GetExecutable() string
}

func GetProcessInfo

func GetProcessInfo(pid int) (*ProcessInfo, error)

Jump to

Keyboard shortcuts

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