|
|
|
@ -5,6 +5,7 @@ package process
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"bytes"
|
|
|
|
|
"context"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
@ -83,6 +84,10 @@ func NewProcess(pid int32) (*Process, error) {
|
|
|
|
|
|
|
|
|
|
// Ppid returns Parent Process ID of the process.
|
|
|
|
|
func (p *Process) Ppid() (int32, error) {
|
|
|
|
|
return p.PpidWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
|
|
|
|
_, ppid, _, _, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return -1, err
|
|
|
|
@ -92,6 +97,10 @@ func (p *Process) Ppid() (int32, error) {
|
|
|
|
|
|
|
|
|
|
// Name returns name of the process.
|
|
|
|
|
func (p *Process) Name() (string, error) {
|
|
|
|
|
return p.NameWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
if p.name == "" {
|
|
|
|
|
if err := p.fillFromStatus(); err != nil {
|
|
|
|
|
return "", err
|
|
|
|
@ -112,23 +121,39 @@ func (p *Process) Tgid() (int32, error) {
|
|
|
|
|
|
|
|
|
|
// Exe returns executable path of the process.
|
|
|
|
|
func (p *Process) Exe() (string, error) {
|
|
|
|
|
return p.ExeWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
return p.fillFromExe()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cmdline returns the command line arguments of the process as a string with
|
|
|
|
|
// each argument separated by 0x20 ascii character.
|
|
|
|
|
func (p *Process) Cmdline() (string, error) {
|
|
|
|
|
return p.CmdlineWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
return p.fillFromCmdline()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CmdlineSlice returns the command line arguments of the process as a slice with each
|
|
|
|
|
// element being an argument.
|
|
|
|
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
|
|
|
|
return p.CmdlineSliceWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
|
|
|
|
return p.fillSliceFromCmdline()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateTime returns created time of the process in milliseconds since the epoch, in UTC.
|
|
|
|
|
func (p *Process) CreateTime() (int64, error) {
|
|
|
|
|
return p.CreateTimeWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
|
|
|
|
_, _, _, createTime, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
@ -138,11 +163,19 @@ func (p *Process) CreateTime() (int64, error) {
|
|
|
|
|
|
|
|
|
|
// Cwd returns current working directory of the process.
|
|
|
|
|
func (p *Process) Cwd() (string, error) {
|
|
|
|
|
return p.CwdWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
return p.fillFromCwd()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parent returns parent Process of the process.
|
|
|
|
|
func (p *Process) Parent() (*Process, error) {
|
|
|
|
|
return p.ParentWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -159,6 +192,10 @@ func (p *Process) Parent() (*Process, error) {
|
|
|
|
|
// Z: Zombie W: Wait L: Lock
|
|
|
|
|
// The charactor is same within all supported platforms.
|
|
|
|
|
func (p *Process) Status() (string, error) {
|
|
|
|
|
return p.StatusWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
@ -168,6 +205,10 @@ func (p *Process) Status() (string, error) {
|
|
|
|
|
|
|
|
|
|
// Uids returns user ids of the process as a slice of the int
|
|
|
|
|
func (p *Process) Uids() ([]int32, error) {
|
|
|
|
|
return p.UidsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return []int32{}, err
|
|
|
|
@ -177,6 +218,10 @@ func (p *Process) Uids() ([]int32, error) {
|
|
|
|
|
|
|
|
|
|
// Gids returns group ids of the process as a slice of the int
|
|
|
|
|
func (p *Process) Gids() ([]int32, error) {
|
|
|
|
|
return p.GidsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return []int32{}, err
|
|
|
|
@ -186,6 +231,10 @@ func (p *Process) Gids() ([]int32, error) {
|
|
|
|
|
|
|
|
|
|
// Terminal returns a terminal which is associated with the process.
|
|
|
|
|
func (p *Process) Terminal() (string, error) {
|
|
|
|
|
return p.TerminalWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
terminal, _, _, _, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return "", err
|
|
|
|
@ -196,6 +245,10 @@ func (p *Process) Terminal() (string, error) {
|
|
|
|
|
// Nice returns a nice value (priority).
|
|
|
|
|
// Notice: gopsutil can not set nice value.
|
|
|
|
|
func (p *Process) Nice() (int32, error) {
|
|
|
|
|
return p.NiceWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
|
|
|
|
_, _, _, _, _, nice, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
@ -205,11 +258,19 @@ func (p *Process) Nice() (int32, error) {
|
|
|
|
|
|
|
|
|
|
// IOnice returns process I/O nice value (priority).
|
|
|
|
|
func (p *Process) IOnice() (int32, error) {
|
|
|
|
|
return p.IOniceWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
|
|
|
|
return 0, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rlimit returns Resource Limits.
|
|
|
|
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
|
|
|
|
return p.RlimitWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|
|
|
|
return p.RlimitUsage(false)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -217,6 +278,10 @@ func (p *Process) Rlimit() ([]RlimitStat, error) {
|
|
|
|
|
// If gatherUsed is true, the currently used value will be gathered and added
|
|
|
|
|
// to the resulting RlimitStat.
|
|
|
|
|
func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
|
|
|
|
return p.RlimitUsageWithContext(context.Background(), gatherUsed)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) RlimitUsageWithContext(ctx context.Context, gatherUsed bool) ([]RlimitStat, error) {
|
|
|
|
|
rlimits, err := p.fillFromLimits()
|
|
|
|
|
if !gatherUsed || err != nil {
|
|
|
|
|
return rlimits, err
|
|
|
|
@ -273,11 +338,19 @@ func (p *Process) RlimitUsage(gatherUsed bool) ([]RlimitStat, error) {
|
|
|
|
|
|
|
|
|
|
// IOCounters returns IO Counters.
|
|
|
|
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
|
|
|
|
return p.IOCountersWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
|
|
|
|
return p.fillFromIO()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NumCtxSwitches returns the number of the context switches of the process.
|
|
|
|
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|
|
|
|
return p.NumCtxSwitchesWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -287,12 +360,20 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|
|
|
|
|
|
|
|
|
// NumFDs returns the number of File Descriptors used by the process.
|
|
|
|
|
func (p *Process) NumFDs() (int32, error) {
|
|
|
|
|
return p.NumFDsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
|
|
|
|
_, fnames, err := p.fillFromfdList()
|
|
|
|
|
return int32(len(fnames)), err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NumThreads returns the number of threads used by the process.
|
|
|
|
|
func (p *Process) NumThreads() (int32, error) {
|
|
|
|
|
return p.NumThreadsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
@ -301,6 +382,10 @@ func (p *Process) NumThreads() (int32, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
|
|
|
|
return p.ThreadsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
|
|
|
|
ret := make(map[int32]*cpu.TimesStat)
|
|
|
|
|
taskPath := common.HostProc(strconv.Itoa(int(p.Pid)), "task")
|
|
|
|
|
|
|
|
|
@ -322,6 +407,10 @@ func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
|
|
|
|
|
|
|
|
|
// Times returns CPU times of the process.
|
|
|
|
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
|
|
|
|
return p.TimesWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
|
|
|
|
_, _, cpuTimes, _, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -333,11 +422,19 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
|
|
|
|
//
|
|
|
|
|
// Notice: Not implemented yet.
|
|
|
|
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
|
|
|
|
return p.CPUAffinityWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
|
|
|
|
return nil, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MemoryInfo returns platform in-dependend memory information, such as RSS, VMS and Swap
|
|
|
|
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
|
|
|
|
return p.MemoryInfoWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
|
|
|
|
meminfo, _, err := p.fillFromStatm()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -347,6 +444,10 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
|
|
|
|
|
|
|
|
|
// MemoryInfoEx returns platform dependend memory information.
|
|
|
|
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
|
|
|
|
return p.MemoryInfoExWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
|
|
|
|
_, memInfoEx, err := p.fillFromStatm()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -356,6 +457,10 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
|
|
|
|
|
|
|
|
|
// Children returns a slice of Process of the process.
|
|
|
|
|
func (p *Process) Children() ([]*Process, error) {
|
|
|
|
|
return p.ChildrenWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
|
|
|
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if pids == nil || len(pids) == 0 {
|
|
|
|
@ -377,6 +482,10 @@ func (p *Process) Children() ([]*Process, error) {
|
|
|
|
|
// OpenFiles returns a slice of OpenFilesStat opend by the process.
|
|
|
|
|
// OpenFilesStat includes a file path and file descriptor.
|
|
|
|
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
|
|
|
|
return p.OpenFilesWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
|
|
|
|
_, ofs, err := p.fillFromfd()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
@ -392,11 +501,19 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, 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 (p *Process) Connections() ([]net.ConnectionStat, error) {
|
|
|
|
|
return p.ConnectionsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
|
|
|
|
|
return net.ConnectionsPid("all", p.Pid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NetIOCounters returns NetIOCounters of the process.
|
|
|
|
|
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
|
|
|
|
return p.NetIOCountersWithContext(context.Background(), pernic)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) NetIOCountersWithContext(ctx context.Context, pernic bool) ([]net.IOCountersStat, error) {
|
|
|
|
|
filename := common.HostProc(strconv.Itoa(int(p.Pid)), "net/dev")
|
|
|
|
|
return net.IOCountersByFile(pernic, filename)
|
|
|
|
|
}
|
|
|
|
@ -404,11 +521,19 @@ func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
|
|
|
|
// IsRunning returns whether the process is running or not.
|
|
|
|
|
// Not implemented yet.
|
|
|
|
|
func (p *Process) IsRunning() (bool, error) {
|
|
|
|
|
return p.IsRunningWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
|
|
|
|
return true, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MemoryMaps get memory maps from /proc/(pid)/smaps
|
|
|
|
|
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
|
|
|
|
return p.MemoryMapsWithContext(context.Background(), grouped)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) MemoryMapsWithContext(ctx context.Context, grouped bool) (*[]MemoryMapsStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
var ret []MemoryMapsStat
|
|
|
|
|
smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps")
|
|
|
|
@ -503,6 +628,10 @@ func limitToInt(val string) (int32, error) {
|
|
|
|
|
|
|
|
|
|
// Get num_fds from /proc/(pid)/limits
|
|
|
|
|
func (p *Process) fillFromLimits() ([]RlimitStat, error) {
|
|
|
|
|
return p.fillFromLimitsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits")
|
|
|
|
|
d, err := os.Open(limitsFile)
|
|
|
|
@ -596,6 +725,10 @@ func (p *Process) fillFromLimits() ([]RlimitStat, error) {
|
|
|
|
|
|
|
|
|
|
// Get list of /proc/(pid)/fd files
|
|
|
|
|
func (p *Process) fillFromfdList() (string, []string, error) {
|
|
|
|
|
return p.fillFromfdListWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromfdListWithContext(ctx context.Context) (string, []string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
statPath := common.HostProc(strconv.Itoa(int(pid)), "fd")
|
|
|
|
|
d, err := os.Open(statPath)
|
|
|
|
@ -609,6 +742,10 @@ func (p *Process) fillFromfdList() (string, []string, error) {
|
|
|
|
|
|
|
|
|
|
// Get num_fds from /proc/(pid)/fd
|
|
|
|
|
func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
|
|
|
|
return p.fillFromfdWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromfdWithContext(ctx context.Context) (int32, []*OpenFilesStat, error) {
|
|
|
|
|
statPath, fnames, err := p.fillFromfdList()
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, nil, err
|
|
|
|
@ -638,6 +775,10 @@ func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
|
|
|
|
|
|
|
|
|
// Get cwd from /proc/(pid)/cwd
|
|
|
|
|
func (p *Process) fillFromCwd() (string, error) {
|
|
|
|
|
return p.fillFromCwdWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromCwdWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
cwdPath := common.HostProc(strconv.Itoa(int(pid)), "cwd")
|
|
|
|
|
cwd, err := os.Readlink(cwdPath)
|
|
|
|
@ -649,6 +790,10 @@ func (p *Process) fillFromCwd() (string, error) {
|
|
|
|
|
|
|
|
|
|
// Get exe from /proc/(pid)/exe
|
|
|
|
|
func (p *Process) fillFromExe() (string, error) {
|
|
|
|
|
return p.fillFromExeWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromExeWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
exePath := common.HostProc(strconv.Itoa(int(pid)), "exe")
|
|
|
|
|
exe, err := os.Readlink(exePath)
|
|
|
|
@ -660,6 +805,10 @@ func (p *Process) fillFromExe() (string, error) {
|
|
|
|
|
|
|
|
|
|
// Get cmdline from /proc/(pid)/cmdline
|
|
|
|
|
func (p *Process) fillFromCmdline() (string, error) {
|
|
|
|
|
return p.fillFromCmdlineWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
|
|
|
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
|
|
|
@ -677,6 +826,10 @@ func (p *Process) fillFromCmdline() (string, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillSliceFromCmdline() ([]string, error) {
|
|
|
|
|
return p.fillSliceFromCmdlineWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillSliceFromCmdlineWithContext(ctx context.Context) ([]string, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
|
|
|
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
|
|
|
@ -700,6 +853,10 @@ func (p *Process) fillSliceFromCmdline() ([]string, error) {
|
|
|
|
|
|
|
|
|
|
// Get IO status from /proc/(pid)/io
|
|
|
|
|
func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
|
|
|
|
return p.fillFromIOWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
ioPath := common.HostProc(strconv.Itoa(int(pid)), "io")
|
|
|
|
|
ioline, err := ioutil.ReadFile(ioPath)
|
|
|
|
@ -739,6 +896,10 @@ func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
|
|
|
|
|
|
|
|
|
// Get memory info from /proc/(pid)/statm
|
|
|
|
|
func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
|
|
|
|
return p.fillFromStatmWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromStatmWithContext(ctx context.Context) (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
memPath := common.HostProc(strconv.Itoa(int(pid)), "statm")
|
|
|
|
|
contents, err := ioutil.ReadFile(memPath)
|
|
|
|
@ -791,6 +952,10 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
|
|
|
|
|
|
|
|
|
// Get various status from /proc/(pid)/status
|
|
|
|
|
func (p *Process) fillFromStatus() error {
|
|
|
|
|
return p.fillFromStatusWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
|
|
|
|
|
contents, err := ioutil.ReadFile(statPath)
|
|
|
|
@ -951,6 +1116,10 @@ func (p *Process) fillFromStatus() error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromTIDStat(tid int32) (string, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
|
|
|
|
return p.fillFromTIDStatWithContext(context.Background(), tid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (string, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
|
|
|
|
pid := p.Pid
|
|
|
|
|
var statPath string
|
|
|
|
|
|
|
|
|
@ -1025,11 +1194,19 @@ func (p *Process) fillFromTIDStat(tid int32) (string, int32, *cpu.TimesStat, int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
|
|
|
|
return p.fillFromStatWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Process) fillFromStatWithContext(ctx context.Context) (string, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
|
|
|
|
return p.fillFromTIDStat(-1)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pids returns a slice of process ID list which are running now.
|
|
|
|
|
func Pids() ([]int32, error) {
|
|
|
|
|
return PidsWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
|
|
|
|
return readPidsFromDir(common.HostProc())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|