|
|
|
@ -56,6 +56,7 @@ type MemoryMapsStat struct {
|
|
|
|
|
Swap uint64 `json:"swap"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// String returns JSON value of the process.
|
|
|
|
|
func (m MemoryMapsStat) String() string {
|
|
|
|
|
s, _ := json.Marshal(m)
|
|
|
|
|
return string(s)
|
|
|
|
@ -74,6 +75,7 @@ func NewProcess(pid int32) (*Process, error) {
|
|
|
|
|
return p, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Ppid returns Parent Process ID of the process.
|
|
|
|
|
func (p *Process) Ppid() (int32, error) {
|
|
|
|
|
_, ppid, _, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -81,6 +83,8 @@ func (p *Process) Ppid() (int32, error) {
|
|
|
|
|
}
|
|
|
|
|
return ppid, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Name returns name of the process.
|
|
|
|
|
func (p *Process) Name() (string, error) {
|
|
|
|
|
if p.name == "" {
|
|
|
|
|
if err := p.fillFromStatus(); err != nil {
|
|
|
|
@ -89,6 +93,8 @@ func (p *Process) Name() (string, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.name, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exe returns executable path of the process.
|
|
|
|
|
func (p *Process) Exe() (string, error) {
|
|
|
|
|
return p.fillFromExe()
|
|
|
|
|
}
|
|
|
|
@ -105,6 +111,7 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
|
|
|
|
return p.fillSliceFromCmdline()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateTime returns created time of the process in seconds since the epoch, in UTC.
|
|
|
|
|
func (p *Process) CreateTime() (int64, error) {
|
|
|
|
|
_, _, _, createTime, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -113,9 +120,12 @@ func (p *Process) CreateTime() (int64, error) {
|
|
|
|
|
return createTime, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cwd returns current working directory of the process.
|
|
|
|
|
func (p *Process) Cwd() (string, error) {
|
|
|
|
|
return p.fillFromCwd()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parent returns parent Process of the process.
|
|
|
|
|
func (p *Process) Parent() (*Process, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -127,7 +137,7 @@ func (p *Process) Parent() (*Process, error) {
|
|
|
|
|
return NewProcess(p.parent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Status returnes the process status.
|
|
|
|
|
// 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
|
|
|
|
@ -139,6 +149,8 @@ func (p *Process) Status() (string, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.status, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Uids returns user ids of the process as a slice of the int
|
|
|
|
|
func (p *Process) Uids() ([]int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -146,6 +158,8 @@ func (p *Process) Uids() ([]int32, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.uids, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Gids returns group ids of the process as a slice of the int
|
|
|
|
|
func (p *Process) Gids() ([]int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -153,6 +167,8 @@ func (p *Process) Gids() ([]int32, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.gids, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Terminal returns a terminal which is associated with the process.
|
|
|
|
|
func (p *Process) Terminal() (string, error) {
|
|
|
|
|
terminal, _, _, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -160,6 +176,9 @@ func (p *Process) Terminal() (string, error) {
|
|
|
|
|
}
|
|
|
|
|
return terminal, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nice returns a nice value (priority).
|
|
|
|
|
// Notice: gopsutil can not set nice value.
|
|
|
|
|
func (p *Process) Nice() (int32, error) {
|
|
|
|
|
_, _, _, _, nice, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -167,15 +186,23 @@ func (p *Process) Nice() (int32, error) {
|
|
|
|
|
}
|
|
|
|
|
return nice, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IOnice returns process I/O nice value (priority).
|
|
|
|
|
func (p *Process) IOnice() (int32, error) {
|
|
|
|
|
return 0, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Rlimit returns Resource Limits.
|
|
|
|
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
|
|
|
|
return nil, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IOCounters returns IO Counters.
|
|
|
|
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
|
|
|
|
return p.fillFromIO()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NumCtxSwitches returns the number of the context switches of the process.
|
|
|
|
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -183,10 +210,14 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.numCtxSwitches, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NumFDs returns the number of File Descriptors used by the process.
|
|
|
|
|
func (p *Process) NumFDs() (int32, error) {
|
|
|
|
|
numFds, _, err := p.fillFromfd()
|
|
|
|
|
return numFds, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NumThreads returns the number of threads used by the process.
|
|
|
|
|
func (p *Process) NumThreads() (int32, error) {
|
|
|
|
|
err := p.fillFromStatus()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -194,10 +225,16 @@ func (p *Process) NumThreads() (int32, error) {
|
|
|
|
|
}
|
|
|
|
|
return p.numThreads, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Threads returns a map of threads
|
|
|
|
|
//
|
|
|
|
|
// Notice: Not implemented yet. always returns empty map.
|
|
|
|
|
func (p *Process) Threads() (map[string]string, error) {
|
|
|
|
|
ret := make(map[string]string, 0)
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Times returns CPU times of the process.
|
|
|
|
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
|
|
|
|
_, _, cpuTimes, _, _, err := p.fillFromStat()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -205,9 +242,15 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
|
|
|
|
}
|
|
|
|
|
return cpuTimes, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CPUAffinity returns CPU affinity of the process.
|
|
|
|
|
//
|
|
|
|
|
// Notice: Not implemented yet.
|
|
|
|
|
func (p *Process) CPUAffinity() ([]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) {
|
|
|
|
|
meminfo, _, err := p.fillFromStatm()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -215,6 +258,8 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
|
|
|
|
}
|
|
|
|
|
return meminfo, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MemoryInfoEx returns platform dependend memory information.
|
|
|
|
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
|
|
|
|
_, memInfoEx, err := p.fillFromStatm()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -223,6 +268,7 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
|
|
|
|
return memInfoEx, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Children returns a slice of Process of the process.
|
|
|
|
|
func (p *Process) Children() ([]*Process, error) {
|
|
|
|
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
|
|
|
|
if err != nil {
|
|
|
|
@ -242,6 +288,8 @@ func (p *Process) Children() ([]*Process, error) {
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OpenFiles returns a slice of OpenFilesStat opend by the process.
|
|
|
|
|
// OpenFilesStat includes a file path and file descriptor.
|
|
|
|
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
|
|
|
|
_, ofs, err := p.fillFromfd()
|
|
|
|
|
if err != nil {
|
|
|
|
@ -255,15 +303,20 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
|
|
|
|
return ret, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 net.ConnectionsPid("all", p.Pid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NetIOCounters returns NetIOCounters of the process.
|
|
|
|
|
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
|
|
|
|
filename := common.HostProc(strconv.Itoa(int(p.Pid)), "net/dev")
|
|
|
|
|
return net.IOCountersByFile(pernic, filename)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsRunning returns whether the process is running or not.
|
|
|
|
|
// Not implemented yet.
|
|
|
|
|
func (p *Process) IsRunning() (bool, error) {
|
|
|
|
|
return true, common.ErrNotImplementedError
|
|
|
|
|
}
|
|
|
|
@ -687,6 +740,7 @@ func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, e
|
|
|
|
|
return terminal, int32(ppid), cpuTimes, createTime, nice, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Pids returns a slice of process ID list which are running now.
|
|
|
|
|
func Pids() ([]int32, error) {
|
|
|
|
|
var ret []int32
|
|
|
|
|
|
|
|
|
|