go-ps – github.com/mitchellh/go-ps Index | Files

package ps

import "github.com/mitchellh/go-ps"

ps provides an API for finding and listing processes in a platform-agnostic way.

NOTE: If you're reading these docs online via GoDocs or some other system, you might only see the Unix docs. This project makes heavy use of platform-specific implementations. We recommend reading the source if you are interested.

Index

Constants

const (
	ERROR_NO_MORE_FILES = 0x12
	MAX_PATH            = 260
)

Some constants from the Windows API

Types

type PROCESSENTRY32

type PROCESSENTRY32 struct {
	Size              uint32
	CntUsage          uint32
	ProcessID         uint32
	DefaultHeapID     uintptr
	ModuleID          uint32
	CntThreads        uint32
	ParentProcessID   uint32
	PriorityClassBase int32
	Flags             uint32
	ExeFile           [MAX_PATH]uint16
}

PROCESSENTRY32 is the Windows API structure that contains a process's information.

type Process

type Process interface {
	// Pid is the process ID for this process.
	Pid() int

	// PPid is the parent process ID for this process.
	PPid() int

	// Executable name running this process. This is not a path to the
	// executable.
	Executable() string
}

Process is the generic interface that is implemented on every platform and provides common operations for processes.

func FindProcess

func FindProcess(pid int) (Process, error)

FindProcess looks up a single process by pid.

Process will be nil and error will be nil if a matching process is not found.

func Processes

func Processes() ([]Process, error)

Processes returns all processes.

This of course will be a point-in-time snapshot of when this method was called. Some operating systems don't provide snapshot capability of the process table, in which case the process table returned might contain ephemeral entities that happened to be running when this was called.

type WindowsProcess

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

WindowsProcess is an implementation of Process for Windows.

func (*WindowsProcess) Executable

func (p *WindowsProcess) Executable() string

func (*WindowsProcess) PPid

func (p *WindowsProcess) PPid() int

func (*WindowsProcess) Pid

func (p *WindowsProcess) Pid() int

Source Files

process.go process_windows.go

Version
v1.0.0 (latest)
Published
Feb 3, 2020
Platform
windows/amd64
Imports
3 packages
Last checked
now

Tools for package owners.