processex

package module
v0.0.0-...-5acc638 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: BSD-2-Clause Imports: 11 Imported by: 0

README

ProcessEx

ProcessEx - find a os.Process (operating system process) by Name (FindByName) or PID (Find), crossplatform, lightly, fast and full compatible with stdlib os.Process.

GoDoc

installation

go get github.com/biter777/processex

usage

	func main() {
		processName := "explorer.exe"
		process, _, err := processex.FindByName(processName)
		if err == processex.ErrNotFound {
			fmt.Printf("Process %v not running", processName)
			os.Exit(0)
		}
		if err != nil {
			fmt.Printf("Process %v find error: %v", processName, err)
			os.Exit(1)
		}
		fmt.Printf("Process %v PID: %v", processName, process.Pid)
	}

options

For more complex options, consult the documentation.

contributing

(c) Biter

Welcome pull requests, bug fixes and issue reports. Before proposing a change, please discuss it first by raising an issue.

Documentation

Overview

Package processex - find a os.Process (operating system process) by Name (FindByName) or PID (Find), crossplatform, lightly, fast and full compatible with stdlib os.Process.

Usage

	func main() {
	process, err := processex.FindByName("explorer.exe")
	if err != nil {
		fmt.Printf("explorer.exe PID: %v", process.Pid)
	}
}

Contributing

Welcome pull requests, bug fixes and issue reports.
Before proposing a change, please discuss it first by raising an issue.

Package processex - find a os.Process (operating system process) by Name (FindByName) or PID (Find), crossplatform, lightly, fast and full compatible with stdlib os.Process.

Usage

	func main() {
		processName := "explorer.exe"
		process, _, err := processex.FindByName(processName)
		if err == processex.ErrNotFound {
			fmt.Printf("Process %v not running", processName)
			os.Exit(0)
		}
		if err != nil {
			fmt.Printf("Process %v find error: %v", processName, err)
			os.Exit(1)
		}
		fmt.Printf("Process %v PID: %v", processName, process.Pid)
}

Contributing

Welcome pull requests, bug fixes and issue reports.
Before proposing a change, please discuss it first by raising an issue.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("process not found")

ErrNotFound - process not found error

Functions

func Find

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

Find looks for a running process by its pid.

The Process it returns can be used to obtain information about the underlying operating system process.

On Unix systems, FindProcess always succeeds and returns a Process for the given pid, regardless of whether the process exists.

func Start

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. The argv slice will become os.Args in the new process, so it normally starts with the program name.

Types

type Finder

type Finder interface {
	FindByName(name string) ([]*os.Process, []*ProcessEx, error)
	FindByPID(pid int) ([]*os.Process, []*ProcessEx, error)
}

Finder - system processes Finder

func NewFinder

func NewFinder() Finder

NewFinder - NewFinder

type ProcessEx

type ProcessEx struct {
	*os.Process
	Name      string
	PID       int
	ParentPID int
}

ProcessEx - os.P

func FindByName

func FindByName(name string) ([]*os.Process, []*ProcessEx, error)

FindByName looks for a running process by its name.

The Process it returns can be used to obtain information about the underlying operating system process.

func FindByPID

func FindByPID(pid int) ([]*os.Process, []*ProcessEx, error)

FindByPID looks for a running process by its PID.

The Process it returns can be used to obtain information about the underlying operating system process.

Jump to

Keyboard shortcuts

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