ps

package module
v0.0.0-...-91aafc9 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 7 Imported by: 62

README

Process List Library for Go

Build Status Build Status Coverage Status GoDoc

go-ps is a library for Go that implements OS-specific APIs to list and manipulate processes in a platform-safe way. The library can find and list processes on Linux, Mac OS X, and Windows.

If you're new to Go, this library has a good amount of advanced Go educational value as well. It uses some advanced features of Go: build tags, accessing DLL methods for Windows, cgo for Darwin, etc.

How it works:

  • Darwin uses sysctl and proc_listpids (for the path) to retrieve the process table, via cgo.
  • Unix uses the procfs at /proc to inspect the process tree.
  • Windows uses the Windows API, and methods such as CreateToolhelp32Snapshot to get a point-in-time snapshot of the process table.

Installation

Install using standard go get:

$ go get github.com/keybase/go-ps

Documentation

Overview

Package 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

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

	// Path is full path to the executable. The path may be unavailable if the
	// exectuable was deleted from the system while it was still running.
	Path() (string, error)
}

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. This may require a full process listing depending on the platform, so consider using os.FindProcess instead. 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 UnixProcess

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

UnixProcess is an implementation of Process that contains Unix-specific fields and information.

func (*UnixProcess) Executable

func (p *UnixProcess) Executable() string

Executable returns process executable name

func (*UnixProcess) PPid

func (p *UnixProcess) PPid() int

PPid returns parent process id

func (*UnixProcess) Path

func (p *UnixProcess) Path() (string, error)

Path returns path to process executable

func (*UnixProcess) Pid

func (p *UnixProcess) Pid() int

Pid returns process id

func (*UnixProcess) Refresh

func (p *UnixProcess) Refresh() error

Refresh reloads all the data associated with this process.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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