gopsutil: Index | Files

package process

import ""

Package binary implements simple translation between numbers and byte sequences and encoding and decoding of varints.

Numbers are translated by reading and writing fixed-size values. A fixed-size value is either a fixed-size arithmetic type (int8, uint8, int16, float32, complex64, ...) or an array or struct containing only fixed-size values.

The varint functions encode and decode single integer values using a variable-length encoding; smaller values require fewer bytes. For a specification, see

This package favors simplicity over efficiency. Clients that require high-performance serialization, especially for large data structures, should look at more advanced solutions such as the encoding/gob package or protocol buffers.


Package Files

binary.go process.go process_linux.go process_linux_amd64.go process_posix.go


const (
    ClockTicks = 100  // C.sysconf(C._SC_CLK_TCK)
    PageSize   = 4096 // C.sysconf(C._SC_PAGE_SIZE)
const (
    PrioProcess = 0 // linux/resource.h


var BigEndian bigEndian

BigEndian is the big-endian implementation of ByteOrder.

var ErrorNoChildren = errors.New("process does not have children")
var LittleEndian littleEndian

LittleEndian is the little-endian implementation of ByteOrder.

func PidExists Uses

func PidExists(pid int32) (bool, error)

func Pids Uses

func Pids() ([]int32, error)

func Read Uses

func Read(r io.Reader, order ByteOrder, data interface{}) error

Read reads structured binary data from r into data. Data must be a pointer to a fixed-size value or a slice of fixed-size values. Bytes read from r are decoded using the specified byte order and written to successive fields of the data. When reading into structs, the field data for fields with blank (_) field names is skipped; i.e., blank field names may be used for padding. When reading into a struct, all non-blank fields must be exported.

func Size Uses

func Size(v interface{}) int

Size returns how many bytes Write would generate to encode the value v, which must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. If v is neither of these, Size returns -1.

func Write Uses

func Write(w io.Writer, order ByteOrder, data interface{}) error

Write writes the binary representation of data into w. Data must be a fixed-size value or a slice of fixed-size values, or a pointer to such data. Bytes written to w are encoded using the specified byte order and read from successive fields of the data. When writing structs, zero values are written for fields with blank (_) field names.

type ByteOrder Uses

type ByteOrder interface {
    Uint16([]byte) uint16
    Uint32([]byte) uint32
    Uint64([]byte) uint64
    PutUint16([]byte, uint16)
    PutUint32([]byte, uint32)
    PutUint64([]byte, uint64)
    String() string

A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.

type IOCountersStat Uses

type IOCountersStat struct {
    ReadCount  uint64 `json:"read_count"`
    WriteCount uint64 `json:"write_count"`
    ReadBytes  uint64 `json:"read_bytes"`
    WriteBytes uint64 `json:"write_bytes"`

func (IOCountersStat) String Uses

func (i IOCountersStat) String() string

type MemoryInfoExStat Uses

type MemoryInfoExStat struct {
    RSS    uint64 `json:"rss"`    // bytes
    VMS    uint64 `json:"vms"`    // bytes
    Shared uint64 `json:"shared"` // bytes
    Text   uint64 `json:"text"`   // bytes
    Lib    uint64 `json:"lib"`    // bytes
    Data   uint64 `json:"data"`   // bytes
    Dirty  uint64 `json:"dirty"`  // bytes

MemoryInfoExStat is different between OSes

func (MemoryInfoExStat) String Uses

func (m MemoryInfoExStat) String() string

type MemoryInfoStat Uses

type MemoryInfoStat struct {
    RSS  uint64 `json:"rss"`  // bytes
    VMS  uint64 `json:"vms"`  // bytes
    Swap uint64 `json:"swap"` // bytes

func (MemoryInfoStat) String Uses

func (m MemoryInfoStat) String() string

type MemoryMapsStat Uses

type MemoryMapsStat struct {
    Path         string `json:"path"`
    Rss          uint64 `json:"rss"`
    Size         uint64 `json:"size"`
    Pss          uint64 `json:"pss"`
    SharedClean  uint64 `json:"shared_clean"`
    SharedDirty  uint64 `json:"shared_dirty"`
    PrivateClean uint64 `json:"private_clean"`
    PrivateDirty uint64 `json:"private_dirty"`
    Referenced   uint64 `json:"referenced"`
    Anonymous    uint64 `json:"anonymous"`
    Swap         uint64 `json:"swap"`

func (MemoryMapsStat) String Uses

func (m MemoryMapsStat) String() string

type NumCtxSwitchesStat Uses

type NumCtxSwitchesStat struct {
    Voluntary   int64 `json:"voluntary"`
    Involuntary int64 `json:"involuntary"`

func (NumCtxSwitchesStat) String Uses

func (p NumCtxSwitchesStat) String() string

type OpenFilesStat Uses

type OpenFilesStat struct {
    Path string `json:"path"`
    Fd   uint64 `json:"fd"`

func (OpenFilesStat) String Uses

func (o OpenFilesStat) String() string

type Process Uses

type Process struct {
    Pid int32 `json:"pid"`
    // contains filtered or unexported fields

func NewProcess Uses

func NewProcess(pid int32) (*Process, error)

Create new Process instance This only stores Pid

func (*Process) CPUAffinity Uses

func (p *Process) CPUAffinity() ([]int32, error)

func (*Process) CPUPercent Uses

func (p *Process) CPUPercent(interval time.Duration) (float64, error)

If interval is 0, return difference from last call(non-blocking). If interval > 0, wait interval sec and return diffrence between start and end.

func (*Process) CPUTimes Uses

func (p *Process) CPUTimes() (*cpu.CPUTimesStat, error)

func (*Process) Children Uses

func (p *Process) Children() ([]*Process, error)

func (*Process) Cmdline Uses

func (p *Process) Cmdline() (string, error)

func (*Process) CmdlineSlice Uses

func (p *Process) CmdlineSlice() ([]string, error)

func (*Process) Connections Uses

func (p *Process) Connections() ([]net.NetConnectionStat, error)

func (*Process) CreateTime Uses

func (p *Process) CreateTime() (int64, error)

func (*Process) Cwd Uses

func (p *Process) Cwd() (string, error)

func (*Process) Exe Uses

func (p *Process) Exe() (string, error)

func (*Process) Gids Uses

func (p *Process) Gids() ([]int32, error)

func (*Process) IOCounters Uses

func (p *Process) IOCounters() (*IOCountersStat, error)

func (*Process) IOnice Uses

func (p *Process) IOnice() (int32, error)

func (*Process) IsRunning Uses

func (p *Process) IsRunning() (bool, error)

func (*Process) Kill Uses

func (p *Process) Kill() error

func (*Process) MemoryInfo Uses

func (p *Process) MemoryInfo() (*MemoryInfoStat, error)

func (*Process) MemoryInfoEx Uses

func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error)

func (*Process) MemoryMaps Uses

func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error)

MemoryMaps get memory maps from /proc/(pid)/smaps

func (*Process) MemoryPercent Uses

func (p *Process) MemoryPercent() (float32, error)

func (*Process) Name Uses

func (p *Process) Name() (string, error)

func (*Process) NetIOCounters Uses

func (p *Process) NetIOCounters(pernic bool) ([]net.NetIOCountersStat, error)

func (*Process) Nice Uses

func (p *Process) Nice() (int32, error)

func (*Process) NumCtxSwitches Uses

func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error)

func (*Process) NumFDs Uses

func (p *Process) NumFDs() (int32, error)

func (*Process) NumThreads Uses

func (p *Process) NumThreads() (int32, error)

func (*Process) OpenFiles Uses

func (p *Process) OpenFiles() ([]OpenFilesStat, error)

func (*Process) Parent Uses

func (p *Process) Parent() (*Process, error)

func (*Process) Ppid Uses

func (p *Process) Ppid() (int32, error)

func (*Process) Resume Uses

func (p *Process) Resume() error

func (*Process) Rlimit Uses

func (p *Process) Rlimit() ([]RlimitStat, error)

func (*Process) SendSignal Uses

func (p *Process) SendSignal(sig syscall.Signal) error

func (*Process) Status Uses

func (p *Process) Status() (string, error)

func (Process) String Uses

func (p Process) String() string

func (*Process) Suspend Uses

func (p *Process) Suspend() error

func (*Process) Terminal Uses

func (p *Process) Terminal() (string, error)

func (*Process) Terminate Uses

func (p *Process) Terminate() error

func (*Process) Threads Uses

func (p *Process) Threads() (map[string]string, error)

func (*Process) Uids Uses

func (p *Process) Uids() ([]int32, error)

func (*Process) Username Uses

func (p *Process) Username() (string, error)

type RlimitStat Uses

type RlimitStat struct {
    Resource int32 `json:"resource"`
    Soft     int32 `json:"soft"`
    Hard     int32 `json:"hard"`

func (RlimitStat) String Uses

func (r RlimitStat) String() string

Package process imports 21 packages (graph). Updated 2018-12-22. Refresh now. Tools for package owners.