gopsutil: github.com/shirou/gopsutil/process Index | Files

package process

import "github.com/shirou/gopsutil/process"

Index

Package Files

process.go process_linux.go process_posix.go

Constants

const (
    RLIMIT_CPU        int32 = 0
    RLIMIT_FSIZE      int32 = 1
    RLIMIT_DATA       int32 = 2
    RLIMIT_STACK      int32 = 3
    RLIMIT_CORE       int32 = 4
    RLIMIT_RSS        int32 = 5
    RLIMIT_NPROC      int32 = 6
    RLIMIT_NOFILE     int32 = 7
    RLIMIT_MEMLOCK    int32 = 8
    RLIMIT_AS         int32 = 9
    RLIMIT_LOCKS      int32 = 10
    RLIMIT_SIGPENDING int32 = 11
    RLIMIT_MSGQUEUE   int32 = 12
    RLIMIT_NICE       int32 = 13
    RLIMIT_RTPRIO     int32 = 14
    RLIMIT_RTTIME     int32 = 15
)

Resource limit constants are from /usr/include/x86_64-linux-gnu/bits/resource.h from libc6-dev package in Ubuntu 16.10

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

Variables

var (
    ErrorNoChildren = errors.New("process does not have children")
)
var PageSize = uint64(os.Getpagesize())

func PidExists Uses

func PidExists(pid int32) (bool, error)

func PidExistsWithContext Uses

func PidExistsWithContext(ctx context.Context, pid int32) (bool, error)

func Pids Uses

func Pids() ([]int32, error)

Pids returns a slice of process ID list which are running now.

func PidsWithContext Uses

func PidsWithContext(ctx context.Context) ([]int32, error)

type IOCountersStat Uses

type IOCountersStat struct {
    ReadCount  uint64 `json:"readCount"`
    WriteCount uint64 `json:"writeCount"`
    ReadBytes  uint64 `json:"readBytes"`
    WriteBytes uint64 `json:"writeBytes"`
}

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
    Data   uint64 `json:"data"`   // bytes
    Stack  uint64 `json:"stack"`  // bytes
    Locked uint64 `json:"locked"` // 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:"sharedClean"`
    SharedDirty  uint64 `json:"sharedDirty"`
    PrivateClean uint64 `json:"privateClean"`
    PrivateDirty uint64 `json:"privateDirty"`
    Referenced   uint64 `json:"referenced"`
    Anonymous    uint64 `json:"anonymous"`
    Swap         uint64 `json:"swap"`
}

func (MemoryMapsStat) String Uses

func (m MemoryMapsStat) String() string

String returns JSON value of the process.

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)

NewProcess creates a new Process instance, it only stores the pid and checks that the process exists. Other method on Process can be used to get more information about the process. An error will be returned if the process does not exist.

func Processes Uses

func Processes() ([]*Process, error)

Process returns a slice of pointers to Process structs for all currently running processes.

func ProcessesWithContext Uses

func ProcessesWithContext(ctx context.Context) ([]*Process, error)

func (*Process) CPUAffinity Uses

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

CPUAffinity returns CPU affinity of the process.

Notice: Not implemented yet.

func (*Process) CPUAffinityWithContext Uses

func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error)

func (*Process) CPUPercent Uses

func (p *Process) CPUPercent() (float64, error)

CPU_Percent returns how many percent of the CPU time this process uses

func (*Process) CPUPercentWithContext Uses

func (p *Process) CPUPercentWithContext(ctx context.Context) (float64, error)

func (*Process) Children Uses

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

Children returns a slice of Process of the process.

func (*Process) ChildrenWithContext Uses

func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error)

func (*Process) Cmdline Uses

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

Cmdline returns the command line arguments of the process as a string with each argument separated by 0x20 ascii character.

func (*Process) CmdlineSlice Uses

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

CmdlineSlice returns the command line arguments of the process as a slice with each element being an argument.

func (*Process) CmdlineSliceWithContext Uses

func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error)

func (*Process) CmdlineWithContext Uses

func (p *Process) CmdlineWithContext(ctx context.Context) (string, error)

func (*Process) Connections Uses

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

Connections returns a slice of net.ConnectionStat used by the process. This returns all kind of the connection. This measn TCP, UDP or UNIX.

func (*Process) ConnectionsWithContext Uses

func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error)

func (*Process) CreateTime Uses

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

CreateTime returns created time of the process in milliseconds since the epoch, in UTC.

func (*Process) CreateTimeWithContext Uses

func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error)

func (*Process) Cwd Uses

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

Cwd returns current working directory of the process.

func (*Process) CwdWithContext Uses

func (p *Process) CwdWithContext(ctx context.Context) (string, error)

func (*Process) Exe Uses

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

Exe returns executable path of the process.

func (*Process) ExeWithContext Uses

func (p *Process) ExeWithContext(ctx context.Context) (string, error)

func (*Process) Gids Uses

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

Gids returns group ids of the process as a slice of the int

func (*Process) GidsWithContext Uses

func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error)

func (*Process) IOCounters Uses

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

IOCounters returns IO Counters.

func (*Process) IOCountersWithContext Uses

func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error)

func (*Process) IOnice Uses

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

IOnice returns process I/O nice value (priority).

func (*Process) IOniceWithContext Uses

func (p *Process) IOniceWithContext(ctx context.Context) (int32, error)

func (*Process) IsRunning Uses

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

IsRunning returns whether the process is running or not. Not implemented yet.

func (*Process) IsRunningWithContext Uses

func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error)

func (*Process) Kill Uses

func (p *Process) Kill() error

Kill sends SIGKILL to the process.

func (*Process) KillWithContext Uses

func (p *Process) KillWithContext(ctx context.Context) error

func (*Process) MemoryInfo Uses

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

MemoryInfo returns platform in-dependend memory information, such as RSS, VMS and Swap

func (*Process) MemoryInfoEx Uses

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

MemoryInfoEx returns platform dependend memory information.

func (*Process) MemoryInfoExWithContext Uses

func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error)

func (*Process) MemoryInfoWithContext Uses

func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error)

func (*Process) MemoryMaps Uses

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

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

func (*Process) MemoryMapsWithContext Uses

func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error)

func (*Process) MemoryPercent Uses

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

MemoryPercent returns how many percent of the total RAM this process uses

func (*Process) MemoryPercentWithContext Uses

func (p *Process) MemoryPercentWithContext(ctx context.Context) (float32, error)

func (*Process) Name Uses

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

Name returns name of the process.

func (*Process) NameWithContext Uses

func (p *Process) NameWithContext(ctx context.Context) (string, error)

func (*Process) NetIOCounters Uses

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

NetIOCounters returns NetIOCounters of the process.

func (*Process) NetIOCountersWithContext Uses

func (p *Process) NetIOCountersWithContext(ctx context.Context, pernic bool) ([]net.IOCountersStat, error)

func (*Process) Nice Uses

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

Nice returns a nice value (priority). Notice: gopsutil can not set nice value.

func (*Process) NiceWithContext Uses

func (p *Process) NiceWithContext(ctx context.Context) (int32, error)

func (*Process) NumCtxSwitches Uses

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

NumCtxSwitches returns the number of the context switches of the process.

func (*Process) NumCtxSwitchesWithContext Uses

func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error)

func (*Process) NumFDs Uses

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

NumFDs returns the number of File Descriptors used by the process.

func (*Process) NumFDsWithContext Uses

func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error)

func (*Process) NumThreads Uses

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

NumThreads returns the number of threads used by the process.

func (*Process) NumThreadsWithContext Uses

func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error)

func (*Process) OpenFiles Uses

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

OpenFiles returns a slice of OpenFilesStat opend by the process. OpenFilesStat includes a file path and file descriptor.

func (*Process) OpenFilesWithContext Uses

func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error)

func (*Process) Parent Uses

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

Parent returns parent Process of the process.

func (*Process) ParentWithContext Uses

func (p *Process) ParentWithContext(ctx context.Context) (*Process, error)

func (*Process) Percent Uses

func (p *Process) Percent(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) PercentWithContext Uses

func (p *Process) PercentWithContext(ctx context.Context, interval time.Duration) (float64, error)

func (*Process) Ppid Uses

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

Ppid returns Parent Process ID of the process.

func (*Process) PpidWithContext Uses

func (p *Process) PpidWithContext(ctx context.Context) (int32, error)

func (*Process) Resume Uses

func (p *Process) Resume() error

Resume sends SIGCONT to the process.

func (*Process) ResumeWithContext Uses

func (p *Process) ResumeWithContext(ctx context.Context) error

func (*Process) Rlimit Uses

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

Rlimit returns Resource Limits.

func (*Process) RlimitUsage Uses

func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error)

RlimitUsage returns Resource Limits. If gatherUsed is true, the currently used value will be gathered and added to the resulting RlimitStat.

func (*Process) RlimitUsageWithContext Uses

func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ([]RlimitStat, error)

func (*Process) RlimitWithContext Uses

func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error)

func (*Process) SendSignal Uses

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

SendSignal sends a unix.Signal to the process. Currently, SIGSTOP, SIGCONT, SIGTERM and SIGKILL are supported.

func (*Process) SendSignalWithContext Uses

func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal) error

func (*Process) Status Uses

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

Status returns the process status. Return value could be one of these. R: Running S: Sleep T: Stop I: Idle Z: Zombie W: Wait L: Lock The charactor is same within all supported platforms.

func (*Process) StatusWithContext Uses

func (p *Process) StatusWithContext(ctx context.Context) (string, error)

func (Process) String Uses

func (p Process) String() string

func (*Process) Suspend Uses

func (p *Process) Suspend() error

Suspend sends SIGSTOP to the process.

func (*Process) SuspendWithContext Uses

func (p *Process) SuspendWithContext(ctx context.Context) error

func (*Process) Terminal Uses

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

Terminal returns a terminal which is associated with the process.

func (*Process) TerminalWithContext Uses

func (p *Process) TerminalWithContext(ctx context.Context) (string, error)

func (*Process) Terminate Uses

func (p *Process) Terminate() error

Terminate sends SIGTERM to the process.

func (*Process) TerminateWithContext Uses

func (p *Process) TerminateWithContext(ctx context.Context) error

func (*Process) Tgid Uses

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

Tgid returns tgid, a Linux-synonym for user-space Pid

func (*Process) Threads Uses

func (p *Process) Threads() (map[int32]*cpu.TimesStat, error)

func (*Process) ThreadsWithContext Uses

func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error)

func (*Process) Times Uses

func (p *Process) Times() (*cpu.TimesStat, error)

Times returns CPU times of the process.

func (*Process) TimesWithContext Uses

func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error)

func (*Process) Uids Uses

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

Uids returns user ids of the process as a slice of the int

func (*Process) UidsWithContext Uses

func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error)

func (*Process) Username Uses

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

Username returns a username of the process.

func (*Process) UsernameWithContext Uses

func (p *Process) UsernameWithContext(ctx context.Context) (string, error)

type RlimitStat Uses

type RlimitStat struct {
    Resource int32  `json:"resource"`
    Soft     int32  `json:"soft"` //TODO too small. needs to be uint64
    Hard     int32  `json:"hard"` //TODO too small. needs to be uint64
    Used     uint64 `json:"used"`
}

func (RlimitStat) String Uses

func (r RlimitStat) String() string

type SignalInfoStat Uses

type SignalInfoStat struct {
    PendingProcess uint64 `json:"pending_process"`
    PendingThread  uint64 `json:"pending_thread"`
    Blocked        uint64 `json:"blocked"`
    Ignored        uint64 `json:"ignored"`
    Caught         uint64 `json:"caught"`
}

Package process imports 22 packages (graph) and is imported by 143 packages. Updated 2018-03-31. Refresh now. Tools for package owners.