Update vendor package github.com/shirou/gopsutil/process, resolves #3881
This commit is contained in:
parent
8b86e64fd8
commit
359e1f3497
48
vendor/github.com/shirou/gopsutil/process/process.go
generated
vendored
48
vendor/github.com/shirou/gopsutil/process/process.go
generated
vendored
|
@ -1,6 +1,7 @@
|
||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
@ -26,9 +27,12 @@ type Process struct {
|
||||||
gids []int32
|
gids []int32
|
||||||
numThreads int32
|
numThreads int32
|
||||||
memInfo *MemoryInfoStat
|
memInfo *MemoryInfoStat
|
||||||
|
sigInfo *SignalInfoStat
|
||||||
|
|
||||||
lastCPUTimes *cpu.TimesStat
|
lastCPUTimes *cpu.TimesStat
|
||||||
lastCPUTime time.Time
|
lastCPUTime time.Time
|
||||||
|
|
||||||
|
tgid int32
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenFilesStat struct {
|
type OpenFilesStat struct {
|
||||||
|
@ -39,13 +43,25 @@ type OpenFilesStat struct {
|
||||||
type MemoryInfoStat struct {
|
type MemoryInfoStat struct {
|
||||||
RSS uint64 `json:"rss"` // bytes
|
RSS uint64 `json:"rss"` // bytes
|
||||||
VMS uint64 `json:"vms"` // 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
|
Swap uint64 `json:"swap"` // bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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"`
|
||||||
|
}
|
||||||
|
|
||||||
type RlimitStat struct {
|
type RlimitStat struct {
|
||||||
Resource int32 `json:"resource"`
|
Resource int32 `json:"resource"`
|
||||||
Soft int32 `json:"soft"`
|
Soft int32 `json:"soft"` //TODO too small. needs to be uint64
|
||||||
Hard int32 `json:"hard"`
|
Hard int32 `json:"hard"` //TODO too small. needs to be uint64
|
||||||
|
Used uint64 `json:"used"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type IOCountersStat struct {
|
type IOCountersStat struct {
|
||||||
|
@ -112,6 +128,10 @@ func (p NumCtxSwitchesStat) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func PidExists(pid int32) (bool, error) {
|
func PidExists(pid int32) (bool, error) {
|
||||||
|
return PidExistsWithContext(context.Background(), pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidExistsWithContext(ctx context.Context, pid int32) (bool, error) {
|
||||||
pids, err := Pids()
|
pids, err := Pids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
|
@ -129,6 +149,10 @@ func PidExists(pid int32) (bool, error) {
|
||||||
// If interval is 0, return difference from last call(non-blocking).
|
// If interval is 0, return difference from last call(non-blocking).
|
||||||
// If interval > 0, wait interval sec and return diffrence between start and end.
|
// If interval > 0, wait interval sec and return diffrence between start and end.
|
||||||
func (p *Process) Percent(interval time.Duration) (float64, error) {
|
func (p *Process) Percent(interval time.Duration) (float64, error) {
|
||||||
|
return p.PercentWithContext(context.Background(), interval)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PercentWithContext(ctx context.Context, interval time.Duration) (float64, error) {
|
||||||
cpuTimes, err := p.Times()
|
cpuTimes, err := p.Times()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -172,6 +196,10 @@ func calculatePercent(t1, t2 *cpu.TimesStat, delta float64, numcpu int) float64
|
||||||
|
|
||||||
// MemoryPercent returns how many percent of the total RAM this process uses
|
// MemoryPercent returns how many percent of the total RAM this process uses
|
||||||
func (p *Process) MemoryPercent() (float32, error) {
|
func (p *Process) MemoryPercent() (float32, error) {
|
||||||
|
return p.MemoryPercentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryPercentWithContext(ctx context.Context) (float32, error) {
|
||||||
machineMemory, err := mem.VirtualMemory()
|
machineMemory, err := mem.VirtualMemory()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -186,20 +214,28 @@ func (p *Process) MemoryPercent() (float32, error) {
|
||||||
|
|
||||||
return (100 * float32(used) / float32(total)), nil
|
return (100 * float32(used) / float32(total)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// CPU_Percent returns how many percent of the CPU time this process uses
|
// CPU_Percent returns how many percent of the CPU time this process uses
|
||||||
func (p *Process) CPUPercent() (float64, error) {
|
func (p *Process) CPUPercent() (float64, error) {
|
||||||
|
return p.CPUPercentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUPercentWithContext(ctx context.Context) (float64, error) {
|
||||||
crt_time, err := p.CreateTime()
|
crt_time, err := p.CreateTime()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cput, err := p.Times()
|
||||||
cpu, err := p.Times()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
created := time.Unix(0, crt_time*int64(time.Millisecond))
|
||||||
return (100 * (cpu.Total()) / float64(time.Now().Unix()-(crt_time/1000))), nil
|
totalTime := time.Since(created).Seconds()
|
||||||
|
if totalTime <= 0 {
|
||||||
|
return 0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 100 * cput.Total() / totalTime, nil
|
||||||
|
}
|
||||||
|
|
161
vendor/github.com/shirou/gopsutil/process/process_darwin.go
generated
vendored
161
vendor/github.com/shirou/gopsutil/process/process_darwin.go
generated
vendored
|
@ -4,6 +4,7 @@ package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -44,6 +45,10 @@ type MemoryMapsStat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
var ret []int32
|
var ret []int32
|
||||||
|
|
||||||
pids, err := callPs("pid", 0, false)
|
pids, err := callPs("pid", 0, false)
|
||||||
|
@ -63,6 +68,10 @@ func Pids() ([]int32, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
r, err := callPs("ppid", p.Pid, false)
|
r, err := callPs("ppid", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -76,6 +85,10 @@ func (p *Process) Ppid() (int32, error) {
|
||||||
return int32(v), err
|
return int32(v), err
|
||||||
}
|
}
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -83,7 +96,14 @@ func (p *Process) Name() (string, error) {
|
||||||
|
|
||||||
return common.IntToString(k.Proc.P_comm[:]), nil
|
return common.IntToString(k.Proc.P_comm[:]), nil
|
||||||
}
|
}
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
lsof_bin, err := exec.LookPath("lsof")
|
lsof_bin, err := exec.LookPath("lsof")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -117,6 +137,10 @@ func (p *Process) Exe() (string, error) {
|
||||||
// Cmdline returns the command line arguments of the process as a string with
|
// Cmdline returns the command line arguments of the process as a string with
|
||||||
// each argument separated by 0x20 ascii character.
|
// each argument separated by 0x20 ascii character.
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
r, err := callPs("command", p.Pid, false)
|
r, err := callPs("command", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -130,6 +154,10 @@ func (p *Process) Cmdline() (string, error) {
|
||||||
// reported as two separate items. In order to do something better CGO would be needed
|
// reported as two separate items. In order to do something better CGO would be needed
|
||||||
// to use the native darwin functions.
|
// to use the native darwin functions.
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
r, err := callPs("command", p.Pid, false)
|
r, err := callPs("command", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -137,6 +165,10 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
return r[0], err
|
return r[0], err
|
||||||
}
|
}
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
r, err := callPs("etime", p.Pid, false)
|
r, err := callPs("etime", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -167,9 +199,17 @@ func (p *Process) CreateTime() (int64, error) {
|
||||||
return start.Unix() * 1000, nil
|
return start.Unix() * 1000, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
rr, err := common.CallLsof(invoke, p.Pid, "-FR")
|
rr, err := common.CallLsof(invoke, p.Pid, "-FR")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -188,6 +228,10 @@ func (p *Process) Parent() (*Process, error) {
|
||||||
return nil, fmt.Errorf("could not find parent line")
|
return nil, fmt.Errorf("could not find parent line")
|
||||||
}
|
}
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
r, err := callPs("state", p.Pid, false)
|
r, err := callPs("state", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -196,6 +240,10 @@ func (p *Process) Status() (string, error) {
|
||||||
return r[0][0], err
|
return r[0][0], err
|
||||||
}
|
}
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -207,6 +255,10 @@ func (p *Process) Uids() ([]int32, error) {
|
||||||
return []int32{userEffectiveUID}, nil
|
return []int32{userEffectiveUID}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -218,6 +270,10 @@ func (p *Process) Gids() ([]int32, error) {
|
||||||
return gids, nil
|
return gids, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
/*
|
/*
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
|
@ -235,6 +291,10 @@ func (p *Process) Terminal() (string, error) {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -242,30 +302,66 @@ func (p *Process) Nice() (int32, error) {
|
||||||
return int32(k.Proc.P_nice), nil
|
return int32(k.Proc.P_nice), nil
|
||||||
}
|
}
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
var rlimit []RlimitStat
|
||||||
|
return rlimit, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
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) {
|
||||||
var rlimit []RlimitStat
|
var rlimit []RlimitStat
|
||||||
return rlimit, common.ErrNotImplementedError
|
return rlimit, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
r, err := callPs("utime,stime", p.Pid, true)
|
r, err := callPs("utime,stime", p.Pid, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
return int32(len(r)), nil
|
return int32(len(r)), nil
|
||||||
}
|
}
|
||||||
func (p *Process) Threads() (map[string]string, error) {
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||||
ret := make(map[string]string, 0)
|
return p.ThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
||||||
|
ret := make(map[int32]*cpu.TimesStat)
|
||||||
return ret, common.ErrNotImplementedError
|
return ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,6 +391,10 @@ func convertCPUTimes(s string) (ret float64, err error) {
|
||||||
return float64(t) / ClockTicks, nil
|
return float64(t) / ClockTicks, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
r, err := callPs("utime,stime", p.Pid, false)
|
r, err := callPs("utime,stime", p.Pid, false)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -318,9 +418,17 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
r, err := callPs("rss,vsize,pagein", p.Pid, false)
|
r, err := callPs("rss,vsize,pagein", p.Pid, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -347,10 +455,18 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
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)
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -367,27 +483,51 @@ func (p *Process) Children() ([]*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
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)
|
return net.ConnectionsPid("all", p.Pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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) {
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
return &ret, common.ErrNotImplementedError
|
return &ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func processes() ([]Process, error) {
|
func Processes() ([]*Process, error) {
|
||||||
results := make([]Process, 0, 50)
|
return ProcessesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
results := []*Process{}
|
||||||
|
|
||||||
mib := []int32{CTLKern, KernProc, KernProcAll, 0}
|
mib := []int32{CTLKern, KernProc, KernProcAll, 0}
|
||||||
buf, length, err := common.CallSyscall(mib)
|
buf, length, err := common.CallSyscall(mib)
|
||||||
|
@ -399,13 +539,6 @@ func processes() ([]Process, error) {
|
||||||
k := KinfoProc{}
|
k := KinfoProc{}
|
||||||
procinfoLen := int(unsafe.Sizeof(k))
|
procinfoLen := int(unsafe.Sizeof(k))
|
||||||
count := int(length / uint64(procinfoLen))
|
count := int(length / uint64(procinfoLen))
|
||||||
/*
|
|
||||||
fmt.Println(length, procinfoLen, count)
|
|
||||||
b := buf[0*procinfoLen : 0*procinfoLen+procinfoLen]
|
|
||||||
fmt.Println(b)
|
|
||||||
kk, err := parseKinfoProc(b)
|
|
||||||
fmt.Printf("%#v", kk)
|
|
||||||
*/
|
|
||||||
|
|
||||||
// parse buf to procs
|
// parse buf to procs
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
|
@ -418,7 +551,7 @@ func processes() ([]Process, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
results = append(results, *p)
|
results = append(results, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
|
@ -439,6 +572,10 @@ func parseKinfoProc(buf []byte) (KinfoProc, error) {
|
||||||
// Returns a proc as defined here:
|
// Returns a proc as defined here:
|
||||||
// http://unix.superglobalmegacorp.com/Net2/newsrc/sys/kinfo_proc.h.html
|
// http://unix.superglobalmegacorp.com/Net2/newsrc/sys/kinfo_proc.h.html
|
||||||
func (p *Process) getKProc() (*KinfoProc, error) {
|
func (p *Process) getKProc() (*KinfoProc, error) {
|
||||||
|
return p.getKProcWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) getKProcWithContext(ctx context.Context) (*KinfoProc, error) {
|
||||||
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
||||||
procK := KinfoProc{}
|
procK := KinfoProc{}
|
||||||
length := uint64(unsafe.Sizeof(procK))
|
length := uint64(unsafe.Sizeof(procK))
|
||||||
|
|
161
vendor/github.com/shirou/gopsutil/process/process_fallback.go
generated
vendored
161
vendor/github.com/shirou/gopsutil/process/process_fallback.go
generated
vendored
|
@ -3,6 +3,7 @@
|
||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/shirou/gopsutil/cpu"
|
"github.com/shirou/gopsutil/cpu"
|
||||||
|
@ -28,6 +29,10 @@ type MemoryInfoExStat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return []int32{}, common.ErrNotImplementedError
|
return []int32{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,110 +41,264 @@ func NewProcess(pid int32) (*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
return []string{}, common.ErrNotImplementedError
|
return []string{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return []int32{}, common.ErrNotImplementedError
|
return []int32{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return []int32{}, common.ErrNotImplementedError
|
return []int32{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
return nil, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Threads() (map[string]string, 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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
func (p *Process) Children() ([]*Process, error) {
|
||||||
|
return p.ChildrenWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
return []OpenFilesStat{}, common.ErrNotImplementedError
|
return []OpenFilesStat{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
||||||
|
return p.ConnectionsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
|
||||||
return []net.ConnectionStat{}, common.ErrNotImplementedError
|
return []net.ConnectionStat{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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) {
|
||||||
return []net.IOCountersStat{}, common.ErrNotImplementedError
|
return []net.IOCountersStat{}, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) SendSignal(sig syscall.Signal) error {
|
func (p *Process) SendSignal(sig syscall.Signal) error {
|
||||||
|
return p.SendSignalWithContext(context.Background(), sig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Suspend() error {
|
func (p *Process) Suspend() error {
|
||||||
|
return p.SuspendWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SuspendWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Resume() error {
|
func (p *Process) Resume() error {
|
||||||
|
return p.ResumeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ResumeWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Terminate() error {
|
func (p *Process) Terminate() error {
|
||||||
|
return p.TerminateWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminateWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Kill() error {
|
func (p *Process) Kill() error {
|
||||||
|
return p.KillWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) KillWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Username() (string, error) {
|
func (p *Process) Username() (string, error) {
|
||||||
|
return p.UsernameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UsernameWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
156
vendor/github.com/shirou/gopsutil/process/process_freebsd.go
generated
vendored
156
vendor/github.com/shirou/gopsutil/process/process_freebsd.go
generated
vendored
|
@ -4,6 +4,7 @@ package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -21,8 +22,12 @@ type MemoryMapsStat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
var ret []int32
|
var ret []int32
|
||||||
procs, err := processes()
|
procs, err := Processes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
@ -35,6 +40,10 @@ func Pids() ([]int32, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -43,6 +52,10 @@ func (p *Process) Ppid() (int32, error) {
|
||||||
return k.Ppid, nil
|
return k.Ppid, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -50,11 +63,22 @@ func (p *Process) Name() (string, error) {
|
||||||
|
|
||||||
return common.IntToString(k.Comm[:]), nil
|
return common.IntToString(k.Comm[:]), nil
|
||||||
}
|
}
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
mib := []int32{CTLKern, KernProc, KernProcArgs, p.Pid}
|
mib := []int32{CTLKern, KernProc, KernProcArgs, p.Pid}
|
||||||
buf, _, err := common.CallSyscall(mib)
|
buf, _, err := common.CallSyscall(mib)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -71,6 +95,10 @@ func (p *Process) Cmdline() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
mib := []int32{CTLKern, KernProc, KernProcArgs, p.Pid}
|
mib := []int32{CTLKern, KernProc, KernProcArgs, p.Pid}
|
||||||
buf, _, err := common.CallSyscall(mib)
|
buf, _, err := common.CallSyscall(mib)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -91,15 +119,31 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
return strParts, nil
|
return strParts, nil
|
||||||
}
|
}
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
return p, common.ErrNotImplementedError
|
return p, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -125,6 +169,10 @@ func (p *Process) Status() (string, error) {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -137,6 +185,10 @@ func (p *Process) Uids() ([]int32, error) {
|
||||||
return uids, nil
|
return uids, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -148,6 +200,10 @@ func (p *Process) Gids() ([]int32, error) {
|
||||||
return gids, nil
|
return gids, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -163,6 +219,10 @@ func (p *Process) Terminal() (string, error) {
|
||||||
return termmap[ttyNr], nil
|
return termmap[ttyNr], nil
|
||||||
}
|
}
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -170,13 +230,33 @@ func (p *Process) Nice() (int32, error) {
|
||||||
return int32(k.Nice), nil
|
return int32(k.Nice), nil
|
||||||
}
|
}
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
var rlimit []RlimitStat
|
||||||
|
return rlimit, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
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) {
|
||||||
var rlimit []RlimitStat
|
var rlimit []RlimitStat
|
||||||
return rlimit, common.ErrNotImplementedError
|
return rlimit, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -187,12 +267,24 @@ func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -200,11 +292,19 @@ func (p *Process) NumThreads() (int32, error) {
|
||||||
|
|
||||||
return k.Numthreads, nil
|
return k.Numthreads, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Threads() (map[string]string, error) {
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||||
ret := make(map[string]string, 0)
|
return p.ThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
||||||
|
ret := make(map[int32]*cpu.TimesStat)
|
||||||
return ret, common.ErrNotImplementedError
|
return ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -216,9 +316,17 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -235,10 +343,18 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
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)
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -255,27 +371,51 @@ func (p *Process) Children() ([]*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
||||||
|
return p.ConnectionsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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) {
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
return &ret, common.ErrNotImplementedError
|
return &ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func processes() ([]Process, error) {
|
func Processes() ([]*Process, error) {
|
||||||
results := make([]Process, 0, 50)
|
return ProcessesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
results := []*Process{}
|
||||||
|
|
||||||
mib := []int32{CTLKern, KernProc, KernProcProc, 0}
|
mib := []int32{CTLKern, KernProc, KernProcProc, 0}
|
||||||
buf, length, err := common.CallSyscall(mib)
|
buf, length, err := common.CallSyscall(mib)
|
||||||
|
@ -298,7 +438,7 @@ func processes() ([]Process, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, *p)
|
results = append(results, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
|
@ -312,6 +452,10 @@ func parseKinfoProc(buf []byte) (KinfoProc, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) getKProc() (*KinfoProc, error) {
|
func (p *Process) getKProc() (*KinfoProc, error) {
|
||||||
|
return p.getKProcWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) getKProcWithContext(ctx context.Context) (*KinfoProc, error) {
|
||||||
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
mib := []int32{CTLKern, KernProc, KernProcPID, p.Pid}
|
||||||
|
|
||||||
buf, length, err := common.CallSyscall(mib)
|
buf, length, err := common.CallSyscall(mib)
|
||||||
|
|
416
vendor/github.com/shirou/gopsutil/process/process_linux.go
generated
vendored
416
vendor/github.com/shirou/gopsutil/process/process_linux.go
generated
vendored
|
@ -5,6 +5,7 @@ package process
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -83,7 +84,11 @@ func NewProcess(pid int32) (*Process, error) {
|
||||||
|
|
||||||
// Ppid returns Parent Process ID of the process.
|
// Ppid returns Parent Process ID of the process.
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
_, ppid, _, _, _, err := p.fillFromStat()
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
|
_, ppid, _, _, _, _, err := p.fillFromStat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return -1, err
|
return -1, err
|
||||||
}
|
}
|
||||||
|
@ -92,6 +97,10 @@ func (p *Process) Ppid() (int32, error) {
|
||||||
|
|
||||||
// Name returns name of the process.
|
// Name returns name of the process.
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
if p.name == "" {
|
if p.name == "" {
|
||||||
if err := p.fillFromStatus(); err != nil {
|
if err := p.fillFromStatus(); err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -100,26 +109,52 @@ func (p *Process) Name() (string, error) {
|
||||||
return p.name, nil
|
return p.name, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tgid returns tgid, a Linux-synonym for user-space Pid
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
if p.tgid == 0 {
|
||||||
|
if err := p.fillFromStatus(); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return p.tgid, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Exe returns executable path of the process.
|
// Exe returns executable path of the process.
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
return p.fillFromExe()
|
return p.fillFromExe()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cmdline returns the command line arguments of the process as a string with
|
// Cmdline returns the command line arguments of the process as a string with
|
||||||
// each argument separated by 0x20 ascii character.
|
// each argument separated by 0x20 ascii character.
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
return p.fillFromCmdline()
|
return p.fillFromCmdline()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CmdlineSlice returns the command line arguments of the process as a slice with each
|
// CmdlineSlice returns the command line arguments of the process as a slice with each
|
||||||
// element being an argument.
|
// element being an argument.
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
return p.fillSliceFromCmdline()
|
return p.fillSliceFromCmdline()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTime returns created time of the process in milliseconds since the epoch, in UTC.
|
// CreateTime returns created time of the process in milliseconds since the epoch, in UTC.
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
_, _, _, createTime, _, err := p.fillFromStat()
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
|
_, _, _, createTime, _, _, err := p.fillFromStat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -128,11 +163,19 @@ func (p *Process) CreateTime() (int64, error) {
|
||||||
|
|
||||||
// Cwd returns current working directory of the process.
|
// Cwd returns current working directory of the process.
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return p.fillFromCwd()
|
return p.fillFromCwd()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parent returns parent Process of the process.
|
// Parent returns parent Process of the process.
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -149,6 +192,10 @@ func (p *Process) Parent() (*Process, error) {
|
||||||
// Z: Zombie W: Wait L: Lock
|
// Z: Zombie W: Wait L: Lock
|
||||||
// The charactor is same within all supported platforms.
|
// The charactor is same within all supported platforms.
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -158,6 +205,10 @@ func (p *Process) Status() (string, error) {
|
||||||
|
|
||||||
// Uids returns user ids of the process as a slice of the int
|
// Uids returns user ids of the process as a slice of the int
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []int32{}, err
|
return []int32{}, err
|
||||||
|
@ -167,6 +218,10 @@ func (p *Process) Uids() ([]int32, error) {
|
||||||
|
|
||||||
// Gids returns group ids of the process as a slice of the int
|
// Gids returns group ids of the process as a slice of the int
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []int32{}, err
|
return []int32{}, err
|
||||||
|
@ -176,17 +231,30 @@ func (p *Process) Gids() ([]int32, error) {
|
||||||
|
|
||||||
// Terminal returns a terminal which is associated with the process.
|
// Terminal returns a terminal which is associated with the process.
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
terminal, _, _, _, _, err := p.fillFromStat()
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
|
t, _, _, _, _, _, err := p.fillFromStat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
termmap, err := getTerminalMap()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
terminal := termmap[t]
|
||||||
return terminal, nil
|
return terminal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nice returns a nice value (priority).
|
// Nice returns a nice value (priority).
|
||||||
// Notice: gopsutil can not set nice value.
|
// Notice: gopsutil can not set nice value.
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
_, _, _, _, nice, err := p.fillFromStat()
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
|
_, _, _, _, _, nice, err := p.fillFromStat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
@ -195,21 +263,99 @@ func (p *Process) Nice() (int32, error) {
|
||||||
|
|
||||||
// IOnice returns process I/O nice value (priority).
|
// IOnice returns process I/O nice value (priority).
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rlimit returns Resource Limits.
|
// Rlimit returns Resource Limits.
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
return p.fillFromLimits()
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
return p.RlimitUsage(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RlimitUsage returns Resource Limits.
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
_, _, _, _, rtprio, nice, err := p.fillFromStat()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := p.fillFromStatus(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := range rlimits {
|
||||||
|
rs := &rlimits[i]
|
||||||
|
switch rs.Resource {
|
||||||
|
case RLIMIT_CPU:
|
||||||
|
times, err := p.Times()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rs.Used = uint64(times.User + times.System)
|
||||||
|
case RLIMIT_DATA:
|
||||||
|
rs.Used = uint64(p.memInfo.Data)
|
||||||
|
case RLIMIT_STACK:
|
||||||
|
rs.Used = uint64(p.memInfo.Stack)
|
||||||
|
case RLIMIT_RSS:
|
||||||
|
rs.Used = uint64(p.memInfo.RSS)
|
||||||
|
case RLIMIT_NOFILE:
|
||||||
|
n, err := p.NumFDs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
rs.Used = uint64(n)
|
||||||
|
case RLIMIT_MEMLOCK:
|
||||||
|
rs.Used = uint64(p.memInfo.Locked)
|
||||||
|
case RLIMIT_AS:
|
||||||
|
rs.Used = uint64(p.memInfo.VMS)
|
||||||
|
case RLIMIT_LOCKS:
|
||||||
|
//TODO we can get the used value from /proc/$pid/locks. But linux doesn't enforce it, so not a high priority.
|
||||||
|
case RLIMIT_SIGPENDING:
|
||||||
|
rs.Used = p.sigInfo.PendingProcess
|
||||||
|
case RLIMIT_NICE:
|
||||||
|
// The rlimit for nice is a little unusual, in that 0 means the niceness cannot be decreased beyond the current value, but it can be increased.
|
||||||
|
// So effectively: if rs.Soft == 0 { rs.Soft = rs.Used }
|
||||||
|
rs.Used = uint64(nice)
|
||||||
|
case RLIMIT_RTPRIO:
|
||||||
|
rs.Used = uint64(rtprio)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rlimits, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// IOCounters returns IO Counters.
|
// IOCounters returns IO Counters.
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
return p.fillFromIO()
|
return p.fillFromIO()
|
||||||
}
|
}
|
||||||
|
|
||||||
// NumCtxSwitches returns the number of the context switches of the process.
|
// NumCtxSwitches returns the number of the context switches of the process.
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -219,12 +365,20 @@ func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
|
||||||
// NumFDs returns the number of File Descriptors used by the process.
|
// NumFDs returns the number of File Descriptors used by the process.
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
_, fnames, err := p.fillFromfdList()
|
_, fnames, err := p.fillFromfdList()
|
||||||
return int32(len(fnames)), err
|
return int32(len(fnames)), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// NumThreads returns the number of threads used by the process.
|
// NumThreads returns the number of threads used by the process.
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
err := p.fillFromStatus()
|
err := p.fillFromStatus()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -232,17 +386,37 @@ func (p *Process) NumThreads() (int32, error) {
|
||||||
return p.numThreads, nil
|
return p.numThreads, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Threads returns a map of threads
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||||
//
|
return p.ThreadsWithContext(context.Background())
|
||||||
// Notice: Not implemented yet. always returns empty map.
|
}
|
||||||
func (p *Process) Threads() (map[string]string, error) {
|
|
||||||
ret := make(map[string]string, 0)
|
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")
|
||||||
|
|
||||||
|
tids, err := readPidsFromDir(taskPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tid := range tids {
|
||||||
|
_, _, cpuTimes, _, _, _, err := p.fillFromTIDStat(tid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
ret[tid] = cpuTimes
|
||||||
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Times returns CPU times of the process.
|
// Times returns CPU times of the process.
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
_, _, cpuTimes, _, _, err := p.fillFromStat()
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
|
_, _, cpuTimes, _, _, _, err := p.fillFromStat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -253,11 +427,19 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
//
|
//
|
||||||
// Notice: Not implemented yet.
|
// Notice: Not implemented yet.
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryInfo returns platform in-dependend memory information, such as RSS, VMS and Swap
|
// MemoryInfo returns platform in-dependend memory information, such as RSS, VMS and Swap
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
meminfo, _, err := p.fillFromStatm()
|
meminfo, _, err := p.fillFromStatm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -267,6 +449,10 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
|
||||||
// MemoryInfoEx returns platform dependend memory information.
|
// MemoryInfoEx returns platform dependend memory information.
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
_, memInfoEx, err := p.fillFromStatm()
|
_, memInfoEx, err := p.fillFromStatm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -276,6 +462,10 @@ func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
|
||||||
// Children returns a slice of Process of the process.
|
// Children returns a slice of Process of the process.
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
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)
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if pids == nil || len(pids) == 0 {
|
if pids == nil || len(pids) == 0 {
|
||||||
|
@ -297,6 +487,10 @@ func (p *Process) Children() ([]*Process, error) {
|
||||||
// OpenFiles returns a slice of OpenFilesStat opend by the process.
|
// OpenFiles returns a slice of OpenFilesStat opend by the process.
|
||||||
// OpenFilesStat includes a file path and file descriptor.
|
// OpenFilesStat includes a file path and file descriptor.
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
_, ofs, err := p.fillFromfd()
|
_, ofs, err := p.fillFromfd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -312,11 +506,19 @@ func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
// Connections returns a slice of net.ConnectionStat used by the process.
|
// Connections returns a slice of net.ConnectionStat used by the process.
|
||||||
// This returns all kind of the connection. This measn TCP, UDP or UNIX.
|
// This returns all kind of the connection. This measn TCP, UDP or UNIX.
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
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)
|
return net.ConnectionsPid("all", p.Pid)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetIOCounters returns NetIOCounters of the process.
|
// NetIOCounters returns NetIOCounters of the process.
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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")
|
filename := common.HostProc(strconv.Itoa(int(p.Pid)), "net/dev")
|
||||||
return net.IOCountersByFile(pernic, filename)
|
return net.IOCountersByFile(pernic, filename)
|
||||||
}
|
}
|
||||||
|
@ -324,11 +526,19 @@ func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
||||||
// IsRunning returns whether the process is running or not.
|
// IsRunning returns whether the process is running or not.
|
||||||
// Not implemented yet.
|
// Not implemented yet.
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// MemoryMaps get memory maps from /proc/(pid)/smaps
|
// MemoryMaps get memory maps from /proc/(pid)/smaps
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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
|
pid := p.Pid
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps")
|
smapsPath := common.HostProc(strconv.Itoa(int(pid)), "smaps")
|
||||||
|
@ -423,6 +633,10 @@ func limitToInt(val string) (int32, error) {
|
||||||
|
|
||||||
// Get num_fds from /proc/(pid)/limits
|
// Get num_fds from /proc/(pid)/limits
|
||||||
func (p *Process) fillFromLimits() ([]RlimitStat, error) {
|
func (p *Process) fillFromLimits() ([]RlimitStat, error) {
|
||||||
|
return p.fillFromLimitsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromLimitsWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits")
|
limitsFile := common.HostProc(strconv.Itoa(int(pid)), "limits")
|
||||||
d, err := os.Open(limitsFile)
|
d, err := os.Open(limitsFile)
|
||||||
|
@ -516,6 +730,10 @@ func (p *Process) fillFromLimits() ([]RlimitStat, error) {
|
||||||
|
|
||||||
// Get list of /proc/(pid)/fd files
|
// Get list of /proc/(pid)/fd files
|
||||||
func (p *Process) fillFromfdList() (string, []string, error) {
|
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
|
pid := p.Pid
|
||||||
statPath := common.HostProc(strconv.Itoa(int(pid)), "fd")
|
statPath := common.HostProc(strconv.Itoa(int(pid)), "fd")
|
||||||
d, err := os.Open(statPath)
|
d, err := os.Open(statPath)
|
||||||
|
@ -529,6 +747,10 @@ func (p *Process) fillFromfdList() (string, []string, error) {
|
||||||
|
|
||||||
// Get num_fds from /proc/(pid)/fd
|
// Get num_fds from /proc/(pid)/fd
|
||||||
func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
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()
|
statPath, fnames, err := p.fillFromfdList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
|
@ -558,6 +780,10 @@ func (p *Process) fillFromfd() (int32, []*OpenFilesStat, error) {
|
||||||
|
|
||||||
// Get cwd from /proc/(pid)/cwd
|
// Get cwd from /proc/(pid)/cwd
|
||||||
func (p *Process) fillFromCwd() (string, error) {
|
func (p *Process) fillFromCwd() (string, error) {
|
||||||
|
return p.fillFromCwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromCwdWithContext(ctx context.Context) (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
cwdPath := common.HostProc(strconv.Itoa(int(pid)), "cwd")
|
cwdPath := common.HostProc(strconv.Itoa(int(pid)), "cwd")
|
||||||
cwd, err := os.Readlink(cwdPath)
|
cwd, err := os.Readlink(cwdPath)
|
||||||
|
@ -569,6 +795,10 @@ func (p *Process) fillFromCwd() (string, error) {
|
||||||
|
|
||||||
// Get exe from /proc/(pid)/exe
|
// Get exe from /proc/(pid)/exe
|
||||||
func (p *Process) fillFromExe() (string, error) {
|
func (p *Process) fillFromExe() (string, error) {
|
||||||
|
return p.fillFromExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromExeWithContext(ctx context.Context) (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
exePath := common.HostProc(strconv.Itoa(int(pid)), "exe")
|
exePath := common.HostProc(strconv.Itoa(int(pid)), "exe")
|
||||||
exe, err := os.Readlink(exePath)
|
exe, err := os.Readlink(exePath)
|
||||||
|
@ -580,6 +810,10 @@ func (p *Process) fillFromExe() (string, error) {
|
||||||
|
|
||||||
// Get cmdline from /proc/(pid)/cmdline
|
// Get cmdline from /proc/(pid)/cmdline
|
||||||
func (p *Process) fillFromCmdline() (string, error) {
|
func (p *Process) fillFromCmdline() (string, error) {
|
||||||
|
return p.fillFromCmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromCmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
||||||
cmdline, err := ioutil.ReadFile(cmdPath)
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
||||||
|
@ -597,6 +831,10 @@ func (p *Process) fillFromCmdline() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) fillSliceFromCmdline() ([]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
|
pid := p.Pid
|
||||||
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
cmdPath := common.HostProc(strconv.Itoa(int(pid)), "cmdline")
|
||||||
cmdline, err := ioutil.ReadFile(cmdPath)
|
cmdline, err := ioutil.ReadFile(cmdPath)
|
||||||
|
@ -620,6 +858,10 @@ func (p *Process) fillSliceFromCmdline() ([]string, error) {
|
||||||
|
|
||||||
// Get IO status from /proc/(pid)/io
|
// Get IO status from /proc/(pid)/io
|
||||||
func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
||||||
|
return p.fillFromIOWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromIOWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
ioPath := common.HostProc(strconv.Itoa(int(pid)), "io")
|
ioPath := common.HostProc(strconv.Itoa(int(pid)), "io")
|
||||||
ioline, err := ioutil.ReadFile(ioPath)
|
ioline, err := ioutil.ReadFile(ioPath)
|
||||||
|
@ -659,6 +901,10 @@ func (p *Process) fillFromIO() (*IOCountersStat, error) {
|
||||||
|
|
||||||
// Get memory info from /proc/(pid)/statm
|
// Get memory info from /proc/(pid)/statm
|
||||||
func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
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
|
pid := p.Pid
|
||||||
memPath := common.HostProc(strconv.Itoa(int(pid)), "statm")
|
memPath := common.HostProc(strconv.Itoa(int(pid)), "statm")
|
||||||
contents, err := ioutil.ReadFile(memPath)
|
contents, err := ioutil.ReadFile(memPath)
|
||||||
|
@ -711,6 +957,10 @@ func (p *Process) fillFromStatm() (*MemoryInfoStat, *MemoryInfoExStat, error) {
|
||||||
|
|
||||||
// Get various status from /proc/(pid)/status
|
// Get various status from /proc/(pid)/status
|
||||||
func (p *Process) fillFromStatus() error {
|
func (p *Process) fillFromStatus() error {
|
||||||
|
return p.fillFromStatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromStatusWithContext(ctx context.Context) error {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
|
statPath := common.HostProc(strconv.Itoa(int(pid)), "status")
|
||||||
contents, err := ioutil.ReadFile(statPath)
|
contents, err := ioutil.ReadFile(statPath)
|
||||||
|
@ -720,6 +970,7 @@ func (p *Process) fillFromStatus() error {
|
||||||
lines := strings.Split(string(contents), "\n")
|
lines := strings.Split(string(contents), "\n")
|
||||||
p.numCtxSwitches = &NumCtxSwitchesStat{}
|
p.numCtxSwitches = &NumCtxSwitchesStat{}
|
||||||
p.memInfo = &MemoryInfoStat{}
|
p.memInfo = &MemoryInfoStat{}
|
||||||
|
p.sigInfo = &SignalInfoStat{}
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
tabParts := strings.SplitN(line, "\t", 2)
|
tabParts := strings.SplitN(line, "\t", 2)
|
||||||
if len(tabParts) < 2 {
|
if len(tabParts) < 2 {
|
||||||
|
@ -749,6 +1000,12 @@ func (p *Process) fillFromStatus() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.parent = int32(pval)
|
p.parent = int32(pval)
|
||||||
|
case "Tgid":
|
||||||
|
pval, err := strconv.ParseInt(value, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.tgid = int32(pval)
|
||||||
case "Uid":
|
case "Uid":
|
||||||
p.uids = make([]int32, 0, 4)
|
p.uids = make([]int32, 0, 4)
|
||||||
for _, i := range strings.Split(value, "\t") {
|
for _, i := range strings.Split(value, "\t") {
|
||||||
|
@ -806,18 +1063,80 @@ func (p *Process) fillFromStatus() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.memInfo.Swap = v * 1024
|
p.memInfo.Swap = v * 1024
|
||||||
|
case "VmData":
|
||||||
|
value := strings.Trim(value, " kB") // remove last "kB"
|
||||||
|
v, err := strconv.ParseUint(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.memInfo.Data = v * 1024
|
||||||
|
case "VmStk":
|
||||||
|
value := strings.Trim(value, " kB") // remove last "kB"
|
||||||
|
v, err := strconv.ParseUint(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.memInfo.Stack = v * 1024
|
||||||
|
case "VmLck":
|
||||||
|
value := strings.Trim(value, " kB") // remove last "kB"
|
||||||
|
v, err := strconv.ParseUint(value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.memInfo.Locked = v * 1024
|
||||||
|
case "SigPnd":
|
||||||
|
v, err := strconv.ParseUint(value, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.sigInfo.PendingThread = v
|
||||||
|
case "ShdPnd":
|
||||||
|
v, err := strconv.ParseUint(value, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.sigInfo.PendingProcess = v
|
||||||
|
case "SigBlk":
|
||||||
|
v, err := strconv.ParseUint(value, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.sigInfo.Blocked = v
|
||||||
|
case "SigIgn":
|
||||||
|
v, err := strconv.ParseUint(value, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.sigInfo.Ignored = v
|
||||||
|
case "SigCgt":
|
||||||
|
v, err := strconv.ParseUint(value, 16, 64)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
p.sigInfo.Caught = v
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, error) {
|
func (p *Process) fillFromTIDStat(tid int32) (uint64, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
||||||
|
return p.fillFromTIDStatWithContext(context.Background(), tid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromTIDStatWithContext(ctx context.Context, tid int32) (uint64, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
statPath := common.HostProc(strconv.Itoa(int(pid)), "stat")
|
var statPath string
|
||||||
|
|
||||||
|
if tid == -1 {
|
||||||
|
statPath = common.HostProc(strconv.Itoa(int(pid)), "stat")
|
||||||
|
} else {
|
||||||
|
statPath = common.HostProc(strconv.Itoa(int(pid)), "task", strconv.Itoa(int(tid)), "stat")
|
||||||
|
}
|
||||||
|
|
||||||
contents, err := ioutil.ReadFile(statPath)
|
contents, err := ioutil.ReadFile(statPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
fields := strings.Fields(string(contents))
|
fields := strings.Fields(string(contents))
|
||||||
|
|
||||||
|
@ -826,28 +1145,23 @@ func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, e
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
termmap, err := getTerminalMap()
|
terminal, err := strconv.ParseUint(fields[i+5], 10, 64)
|
||||||
terminal := ""
|
|
||||||
if err == nil {
|
|
||||||
t, err := strconv.ParseUint(fields[i+5], 10, 64)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
|
||||||
terminal = termmap[t]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ppid, err := strconv.ParseInt(fields[i+2], 10, 32)
|
ppid, err := strconv.ParseInt(fields[i+2], 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
utime, err := strconv.ParseFloat(fields[i+12], 64)
|
utime, err := strconv.ParseFloat(fields[i+12], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
stime, err := strconv.ParseFloat(fields[i+13], 64)
|
stime, err := strconv.ParseFloat(fields[i+13], 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cpuTimes := &cpu.TimesStat{
|
cpuTimes := &cpu.TimesStat{
|
||||||
|
@ -859,24 +1173,72 @@ func (p *Process) fillFromStat() (string, int32, *cpu.TimesStat, int64, int32, e
|
||||||
bootTime, _ := host.BootTime()
|
bootTime, _ := host.BootTime()
|
||||||
t, err := strconv.ParseUint(fields[i+20], 10, 64)
|
t, err := strconv.ParseUint(fields[i+20], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", 0, nil, 0, 0, err
|
return 0, 0, nil, 0, 0, 0, err
|
||||||
}
|
}
|
||||||
ctime := (t / uint64(ClockTicks)) + uint64(bootTime)
|
ctime := (t / uint64(ClockTicks)) + uint64(bootTime)
|
||||||
createTime := int64(ctime * 1000)
|
createTime := int64(ctime * 1000)
|
||||||
|
|
||||||
|
rtpriority, err := strconv.ParseInt(fields[i+16], 10, 32)
|
||||||
|
if rtpriority < 0 {
|
||||||
|
rtpriority = rtpriority*-1 - 1
|
||||||
|
} else {
|
||||||
|
rtpriority = 0
|
||||||
|
}
|
||||||
|
|
||||||
// p.Nice = mustParseInt32(fields[18])
|
// p.Nice = mustParseInt32(fields[18])
|
||||||
// use syscall instead of parse Stat file
|
// use syscall instead of parse Stat file
|
||||||
snice, _ := unix.Getpriority(PrioProcess, int(pid))
|
snice, _ := unix.Getpriority(PrioProcess, int(pid))
|
||||||
nice := int32(snice) // FIXME: is this true?
|
nice := int32(snice) // FIXME: is this true?
|
||||||
|
|
||||||
return terminal, int32(ppid), cpuTimes, createTime, nice, nil
|
return terminal, int32(ppid), cpuTimes, createTime, uint32(rtpriority), nice, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromStat() (uint64, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
||||||
|
return p.fillFromStatWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) fillFromStatWithContext(ctx context.Context) (uint64, int32, *cpu.TimesStat, int64, uint32, int32, error) {
|
||||||
|
return p.fillFromTIDStat(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pids returns a slice of process ID list which are running now.
|
// Pids returns a slice of process ID list which are running now.
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
|
return readPidsFromDir(common.HostProc())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process returns a slice of pointers to Process structs for all
|
||||||
|
// currently running processes.
|
||||||
|
func Processes() ([]*Process, error) {
|
||||||
|
return ProcessesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
out := []*Process{}
|
||||||
|
|
||||||
|
pids, err := Pids()
|
||||||
|
if err != nil {
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, pid := range pids {
|
||||||
|
p, err := NewProcess(pid)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
out = append(out, p)
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readPidsFromDir(path string) ([]int32, error) {
|
||||||
var ret []int32
|
var ret []int32
|
||||||
|
|
||||||
d, err := os.Open(common.HostProc())
|
d, err := os.Open(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
160
vendor/github.com/shirou/gopsutil/process/process_openbsd.go
generated
vendored
160
vendor/github.com/shirou/gopsutil/process/process_openbsd.go
generated
vendored
|
@ -15,6 +15,7 @@ import (
|
||||||
net "github.com/shirou/gopsutil/net"
|
net "github.com/shirou/gopsutil/net"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
import "context"
|
||||||
|
|
||||||
// MemoryInfoExStat is different between OSes
|
// MemoryInfoExStat is different between OSes
|
||||||
type MemoryInfoExStat struct {
|
type MemoryInfoExStat struct {
|
||||||
|
@ -24,8 +25,12 @@ type MemoryMapsStat struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
var ret []int32
|
var ret []int32
|
||||||
procs, err := processes()
|
procs, err := Processes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
@ -38,6 +43,10 @@ func Pids() ([]int32, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -46,6 +55,10 @@ func (p *Process) Ppid() (int32, error) {
|
||||||
return k.Ppid, nil
|
return k.Ppid, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -53,11 +66,22 @@ func (p *Process) Name() (string, error) {
|
||||||
|
|
||||||
return common.IntToString(k.Comm[:]), nil
|
return common.IntToString(k.Comm[:]), nil
|
||||||
}
|
}
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv}
|
mib := []int32{CTLKern, KernProcArgs, p.Pid, KernProcArgv}
|
||||||
buf, _, err := common.CallSyscall(mib)
|
buf, _, err := common.CallSyscall(mib)
|
||||||
|
|
||||||
|
@ -81,6 +105,10 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
argv, err := p.CmdlineSlice()
|
argv, err := p.CmdlineSlice()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -89,15 +117,31 @@ func (p *Process) Cmdline() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
return p, common.ErrNotImplementedError
|
return p, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -119,6 +163,10 @@ func (p *Process) Status() (string, error) {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -131,6 +179,10 @@ func (p *Process) Uids() ([]int32, error) {
|
||||||
return uids, nil
|
return uids, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -142,6 +194,10 @@ func (p *Process) Gids() ([]int32, error) {
|
||||||
return gids, nil
|
return gids, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -157,6 +213,10 @@ func (p *Process) Terminal() (string, error) {
|
||||||
return termmap[ttyNr], nil
|
return termmap[ttyNr], nil
|
||||||
}
|
}
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -164,13 +224,33 @@ func (p *Process) Nice() (int32, error) {
|
||||||
return int32(k.Nice), nil
|
return int32(k.Nice), nil
|
||||||
}
|
}
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
var rlimit []RlimitStat
|
||||||
|
return rlimit, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
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) {
|
||||||
var rlimit []RlimitStat
|
var rlimit []RlimitStat
|
||||||
return rlimit, common.ErrNotImplementedError
|
return rlimit, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -181,20 +261,40 @@ func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
/* not supported, just return 1 */
|
/* not supported, just return 1 */
|
||||||
return 1, nil
|
return 1, nil
|
||||||
}
|
}
|
||||||
func (p *Process) Threads() (map[string]string, error) {
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||||
ret := make(map[string]string, 0)
|
return p.ThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
||||||
|
ret := make(map[int32]*cpu.TimesStat)
|
||||||
return ret, common.ErrNotImplementedError
|
return ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -206,9 +306,17 @@ func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
k, err := p.getKProc()
|
k, err := p.getKProc()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -225,10 +333,18 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
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)
|
pids, err := common.CallPgrep(invoke, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -245,27 +361,51 @@ func (p *Process) Children() ([]*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
||||||
|
return p.ConnectionsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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) {
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
return &ret, common.ErrNotImplementedError
|
return &ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func processes() ([]Process, error) {
|
func Processes() ([]*Process, error) {
|
||||||
results := make([]Process, 0, 50)
|
return ProcessesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
results := []*Process{}
|
||||||
|
|
||||||
buf, length, err := CallKernProcSyscall(KernProcAll, 0)
|
buf, length, err := CallKernProcSyscall(KernProcAll, 0)
|
||||||
|
|
||||||
|
@ -288,7 +428,7 @@ func processes() ([]Process, error) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
results = append(results, *p)
|
results = append(results, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
|
@ -302,6 +442,10 @@ func parseKinfoProc(buf []byte) (KinfoProc, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) getKProc() (*KinfoProc, error) {
|
func (p *Process) getKProc() (*KinfoProc, error) {
|
||||||
|
return p.getKProcWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) getKProcWithContext(ctx context.Context) (*KinfoProc, error) {
|
||||||
buf, length, err := CallKernProcSyscall(KernProcPID, p.Pid)
|
buf, length, err := CallKernProcSyscall(KernProcPID, p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -324,6 +468,10 @@ func NewProcess(pid int32) (*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func CallKernProcSyscall(op int32, arg int32) ([]byte, uint64, error) {
|
func CallKernProcSyscall(op int32, arg int32) ([]byte, uint64, error) {
|
||||||
|
return CallKernProcSyscallWithContext(context.Background(), op, arg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func CallKernProcSyscallWithContext(ctx context.Context, op int32, arg int32) ([]byte, uint64, error) {
|
||||||
mib := []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, 0}
|
mib := []int32{CTLKern, KernProc, op, arg, sizeOfKinfoProc, 0}
|
||||||
mibptr := unsafe.Pointer(&mib[0])
|
mibptr := unsafe.Pointer(&mib[0])
|
||||||
miblen := uint64(len(mib))
|
miblen := uint64(len(mib))
|
||||||
|
|
25
vendor/github.com/shirou/gopsutil/process/process_posix.go
generated
vendored
25
vendor/github.com/shirou/gopsutil/process/process_posix.go
generated
vendored
|
@ -3,6 +3,7 @@
|
||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -65,6 +66,10 @@ func getTerminalMap() (map[uint64]string, error) {
|
||||||
// SendSignal sends a unix.Signal to the process.
|
// SendSignal sends a unix.Signal to the process.
|
||||||
// Currently, SIGSTOP, SIGCONT, SIGTERM and SIGKILL are supported.
|
// Currently, SIGSTOP, SIGCONT, SIGTERM and SIGKILL are supported.
|
||||||
func (p *Process) SendSignal(sig syscall.Signal) error {
|
func (p *Process) SendSignal(sig syscall.Signal) error {
|
||||||
|
return p.SendSignalWithContext(context.Background(), sig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SendSignalWithContext(ctx context.Context, sig syscall.Signal) error {
|
||||||
process, err := os.FindProcess(int(p.Pid))
|
process, err := os.FindProcess(int(p.Pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -80,26 +85,46 @@ func (p *Process) SendSignal(sig syscall.Signal) error {
|
||||||
|
|
||||||
// Suspend sends SIGSTOP to the process.
|
// Suspend sends SIGSTOP to the process.
|
||||||
func (p *Process) Suspend() error {
|
func (p *Process) Suspend() error {
|
||||||
|
return p.SuspendWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SuspendWithContext(ctx context.Context) error {
|
||||||
return p.SendSignal(unix.SIGSTOP)
|
return p.SendSignal(unix.SIGSTOP)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resume sends SIGCONT to the process.
|
// Resume sends SIGCONT to the process.
|
||||||
func (p *Process) Resume() error {
|
func (p *Process) Resume() error {
|
||||||
|
return p.ResumeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ResumeWithContext(ctx context.Context) error {
|
||||||
return p.SendSignal(unix.SIGCONT)
|
return p.SendSignal(unix.SIGCONT)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Terminate sends SIGTERM to the process.
|
// Terminate sends SIGTERM to the process.
|
||||||
func (p *Process) Terminate() error {
|
func (p *Process) Terminate() error {
|
||||||
|
return p.TerminateWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminateWithContext(ctx context.Context) error {
|
||||||
return p.SendSignal(unix.SIGTERM)
|
return p.SendSignal(unix.SIGTERM)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kill sends SIGKILL to the process.
|
// Kill sends SIGKILL to the process.
|
||||||
func (p *Process) Kill() error {
|
func (p *Process) Kill() error {
|
||||||
|
return p.KillWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) KillWithContext(ctx context.Context) error {
|
||||||
return p.SendSignal(unix.SIGKILL)
|
return p.SendSignal(unix.SIGKILL)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Username returns a username of the process.
|
// Username returns a username of the process.
|
||||||
func (p *Process) Username() (string, error) {
|
func (p *Process) Username() (string, error) {
|
||||||
|
return p.UsernameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UsernameWithContext(ctx context.Context) (string, error) {
|
||||||
uids, err := p.Uids()
|
uids, err := p.Uids()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
299
vendor/github.com/shirou/gopsutil/process/process_windows.go
generated
vendored
299
vendor/github.com/shirou/gopsutil/process/process_windows.go
generated
vendored
|
@ -3,7 +3,9 @@
|
||||||
package process
|
package process
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
@ -93,35 +95,57 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Pids() ([]int32, error) {
|
func Pids() ([]int32, error) {
|
||||||
|
return PidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func PidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
|
// inspired by https://gist.github.com/henkman/3083408
|
||||||
|
// and https://github.com/giampaolo/psutil/blob/1c3a15f637521ba5c0031283da39c733fda53e4c/psutil/arch/windows/process_info.c#L315-L329
|
||||||
var ret []int32
|
var ret []int32
|
||||||
|
var read uint32 = 0
|
||||||
|
var psSize uint32 = 1024
|
||||||
|
const dwordSize uint32 = 4
|
||||||
|
|
||||||
procs, err := processes()
|
for {
|
||||||
if err != nil {
|
ps := make([]uint32, psSize)
|
||||||
|
if !w32.EnumProcesses(ps, uint32(len(ps)), &read) {
|
||||||
|
return nil, fmt.Errorf("could not get w32.EnumProcesses")
|
||||||
|
}
|
||||||
|
if uint32(len(ps)) == read { // ps buffer was too small to host every results, retry with a bigger one
|
||||||
|
psSize += 1024
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, pid := range ps[:read/dwordSize] {
|
||||||
|
ret = append(ret, int32(pid))
|
||||||
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, proc := range procs {
|
|
||||||
ret = append(ret, proc.Pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Ppid() (int32, error) {
|
func (p *Process) Ppid() (int32, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
return p.PpidWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) PpidWithContext(ctx context.Context) (int32, error) {
|
||||||
|
ppid, _, _, err := getFromSnapProcess(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
return ppid, nil
|
||||||
return int32(dst[0].ParentProcessID), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetWin32Proc(pid int32) ([]Win32_Process, error) {
|
func GetWin32Proc(pid int32) ([]Win32_Process, error) {
|
||||||
|
return GetWin32ProcWithContext(context.Background(), pid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetWin32ProcWithContext(ctx context.Context, pid int32) ([]Win32_Process, error) {
|
||||||
var dst []Win32_Process
|
var dst []Win32_Process
|
||||||
query := fmt.Sprintf("WHERE ProcessId = %d", pid)
|
query := fmt.Sprintf("WHERE ProcessId = %d", pid)
|
||||||
q := wmi.CreateQuery(&dst, query)
|
q := wmi.CreateQuery(&dst, query)
|
||||||
|
err := common.WMIQueryWithContext(ctx, q, &dst)
|
||||||
if err := wmi.Query(q, &dst); err != nil {
|
if err != nil {
|
||||||
return []Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err)
|
return []Win32_Process{}, fmt.Errorf("could not get win32Proc: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,14 +157,26 @@ func GetWin32Proc(pid int32) ([]Win32_Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Name() (string, error) {
|
func (p *Process) Name() (string, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
return p.NameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NameWithContext(ctx context.Context) (string, error) {
|
||||||
|
_, _, name, err := getFromSnapProcess(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not get Name: %s", err)
|
return "", fmt.Errorf("could not get Name: %s", err)
|
||||||
}
|
}
|
||||||
return dst[0].Name, nil
|
return name, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) Tgid() (int32, error) {
|
||||||
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Exe() (string, error) {
|
func (p *Process) Exe() (string, error) {
|
||||||
|
return p.ExeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ExeWithContext(ctx context.Context) (string, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not get ExecutablePath: %s", err)
|
return "", fmt.Errorf("could not get ExecutablePath: %s", err)
|
||||||
|
@ -149,6 +185,10 @@ func (p *Process) Exe() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Cmdline() (string, error) {
|
func (p *Process) Cmdline() (string, error) {
|
||||||
|
return p.CmdlineWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineWithContext(ctx context.Context) (string, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("could not get CommandLine: %s", err)
|
return "", fmt.Errorf("could not get CommandLine: %s", err)
|
||||||
|
@ -160,6 +200,10 @@ func (p *Process) Cmdline() (string, error) {
|
||||||
// element being an argument. This merely returns the CommandLine informations passed
|
// element being an argument. This merely returns the CommandLine informations passed
|
||||||
// to the process split on the 0x20 ASCII character.
|
// to the process split on the 0x20 ASCII character.
|
||||||
func (p *Process) CmdlineSlice() ([]string, error) {
|
func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
|
return p.CmdlineSliceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CmdlineSliceWithContext(ctx context.Context) ([]string, error) {
|
||||||
cmdline, err := p.Cmdline()
|
cmdline, err := p.Cmdline()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -168,6 +212,10 @@ func (p *Process) CmdlineSlice() ([]string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) CreateTime() (int64, error) {
|
func (p *Process) CreateTime() (int64, error) {
|
||||||
|
return p.CreateTimeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CreateTimeWithContext(ctx context.Context) (int64, error) {
|
||||||
ru, err := getRusage(p.Pid)
|
ru, err := getRusage(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("could not get CreationDate: %s", err)
|
return 0, fmt.Errorf("could not get CreationDate: %s", err)
|
||||||
|
@ -177,9 +225,17 @@ func (p *Process) CreateTime() (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Cwd() (string, error) {
|
func (p *Process) Cwd() (string, error) {
|
||||||
|
return p.CwdWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CwdWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Parent() (*Process, error) {
|
func (p *Process) Parent() (*Process, error) {
|
||||||
|
return p.ParentWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ParentWithContext(ctx context.Context) (*Process, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not get ParentProcessID: %s", err)
|
return nil, fmt.Errorf("could not get ParentProcessID: %s", err)
|
||||||
|
@ -188,9 +244,17 @@ func (p *Process) Parent() (*Process, error) {
|
||||||
return NewProcess(int32(dst[0].ParentProcessID))
|
return NewProcess(int32(dst[0].ParentProcessID))
|
||||||
}
|
}
|
||||||
func (p *Process) Status() (string, error) {
|
func (p *Process) Status() (string, error) {
|
||||||
|
return p.StatusWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) StatusWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Username() (string, error) {
|
func (p *Process) Username() (string, error) {
|
||||||
|
return p.UsernameWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UsernameWithContext(ctx context.Context) (string, error) {
|
||||||
pid := p.Pid
|
pid := p.Pid
|
||||||
// 0x1000 is PROCESS_QUERY_LIMITED_INFORMATION
|
// 0x1000 is PROCESS_QUERY_LIMITED_INFORMATION
|
||||||
c, err := syscall.OpenProcess(0x1000, false, uint32(pid))
|
c, err := syscall.OpenProcess(0x1000, false, uint32(pid))
|
||||||
|
@ -212,20 +276,36 @@ func (p *Process) Username() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Uids() ([]int32, error) {
|
func (p *Process) Uids() ([]int32, error) {
|
||||||
|
return p.UidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) UidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
var uids []int32
|
var uids []int32
|
||||||
|
|
||||||
return uids, common.ErrNotImplementedError
|
return uids, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Gids() ([]int32, error) {
|
func (p *Process) Gids() ([]int32, error) {
|
||||||
|
return p.GidsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) GidsWithContext(ctx context.Context) ([]int32, error) {
|
||||||
var gids []int32
|
var gids []int32
|
||||||
return gids, common.ErrNotImplementedError
|
return gids, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Terminal() (string, error) {
|
func (p *Process) Terminal() (string, error) {
|
||||||
|
return p.TerminalWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminalWithContext(ctx context.Context) (string, error) {
|
||||||
return "", common.ErrNotImplementedError
|
return "", common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nice returnes priority in Windows
|
// Nice returnes priority in Windows
|
||||||
func (p *Process) Nice() (int32, error) {
|
func (p *Process) Nice() (int32, error) {
|
||||||
|
return p.NiceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NiceWithContext(ctx context.Context) (int32, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("could not get Priority: %s", err)
|
return 0, fmt.Errorf("could not get Priority: %s", err)
|
||||||
|
@ -233,15 +313,36 @@ func (p *Process) Nice() (int32, error) {
|
||||||
return int32(dst[0].Priority), nil
|
return int32(dst[0].Priority), nil
|
||||||
}
|
}
|
||||||
func (p *Process) IOnice() (int32, error) {
|
func (p *Process) IOnice() (int32, error) {
|
||||||
|
return p.IOniceWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOniceWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
func (p *Process) Rlimit() ([]RlimitStat, error) {
|
||||||
|
return p.RlimitWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) RlimitWithContext(ctx context.Context) ([]RlimitStat, error) {
|
||||||
|
var rlimit []RlimitStat
|
||||||
|
|
||||||
|
return rlimit, common.ErrNotImplementedError
|
||||||
|
}
|
||||||
|
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) {
|
||||||
var rlimit []RlimitStat
|
var rlimit []RlimitStat
|
||||||
|
|
||||||
return rlimit, common.ErrNotImplementedError
|
return rlimit, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
|
return p.IOCountersWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IOCountersWithContext(ctx context.Context) (*IOCountersStat, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil || len(dst) == 0 {
|
if err != nil || len(dst) == 0 {
|
||||||
return nil, fmt.Errorf("could not get Win32Proc: %s", err)
|
return nil, fmt.Errorf("could not get Win32Proc: %s", err)
|
||||||
|
@ -256,29 +357,77 @@ func (p *Process) IOCounters() (*IOCountersStat, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
func (p *Process) NumCtxSwitches() (*NumCtxSwitchesStat, error) {
|
||||||
|
return p.NumCtxSwitchesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumCtxSwitchesWithContext(ctx context.Context) (*NumCtxSwitchesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumFDs() (int32, error) {
|
func (p *Process) NumFDs() (int32, error) {
|
||||||
|
return p.NumFDsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumFDsWithContext(ctx context.Context) (int32, error) {
|
||||||
return 0, common.ErrNotImplementedError
|
return 0, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) NumThreads() (int32, error) {
|
func (p *Process) NumThreads() (int32, error) {
|
||||||
|
return p.NumThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) NumThreadsWithContext(ctx context.Context) (int32, error) {
|
||||||
dst, err := GetWin32Proc(p.Pid)
|
dst, err := GetWin32Proc(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("could not get ThreadCount: %s", err)
|
return 0, fmt.Errorf("could not get ThreadCount: %s", err)
|
||||||
}
|
}
|
||||||
return int32(dst[0].ThreadCount), nil
|
return int32(dst[0].ThreadCount), nil
|
||||||
}
|
}
|
||||||
func (p *Process) Threads() (map[string]string, error) {
|
func (p *Process) Threads() (map[int32]*cpu.TimesStat, error) {
|
||||||
ret := make(map[string]string, 0)
|
return p.ThreadsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ThreadsWithContext(ctx context.Context) (map[int32]*cpu.TimesStat, error) {
|
||||||
|
ret := make(map[int32]*cpu.TimesStat)
|
||||||
return ret, common.ErrNotImplementedError
|
return ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Times() (*cpu.TimesStat, error) {
|
func (p *Process) Times() (*cpu.TimesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return p.TimesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TimesWithContext(ctx context.Context) (*cpu.TimesStat, error) {
|
||||||
|
sysTimes, err := getProcessCPUTimes(p.Pid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// User and kernel times are represented as a FILETIME structure
|
||||||
|
// wich contains a 64-bit value representing the number of
|
||||||
|
// 100-nanosecond intervals since January 1, 1601 (UTC):
|
||||||
|
// http://msdn.microsoft.com/en-us/library/ms724284(VS.85).aspx
|
||||||
|
// To convert it into a float representing the seconds that the
|
||||||
|
// process has executed in user/kernel mode I borrowed the code
|
||||||
|
// below from psutil's _psutil_windows.c, and in turn from Python's
|
||||||
|
// Modules/posixmodule.c
|
||||||
|
|
||||||
|
user := float64(sysTimes.UserTime.HighDateTime)*429.4967296 + float64(sysTimes.UserTime.LowDateTime)*1e-7
|
||||||
|
kernel := float64(sysTimes.KernelTime.HighDateTime)*429.4967296 + float64(sysTimes.KernelTime.LowDateTime)*1e-7
|
||||||
|
|
||||||
|
return &cpu.TimesStat{
|
||||||
|
User: user,
|
||||||
|
System: kernel,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
func (p *Process) CPUAffinity() ([]int32, error) {
|
func (p *Process) CPUAffinity() ([]int32, error) {
|
||||||
|
return p.CPUAffinityWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) CPUAffinityWithContext(ctx context.Context) ([]int32, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
|
return p.MemoryInfoWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoWithContext(ctx context.Context) (*MemoryInfoStat, error) {
|
||||||
mem, err := getMemoryInfo(p.Pid)
|
mem, err := getMemoryInfo(p.Pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -292,46 +441,74 @@ func (p *Process) MemoryInfo() (*MemoryInfoStat, error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
func (p *Process) MemoryInfoEx() (*MemoryInfoExStat, error) {
|
||||||
|
return p.MemoryInfoExWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) MemoryInfoExWithContext(ctx context.Context) (*MemoryInfoExStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Children() ([]*Process, error) {
|
func (p *Process) Children() ([]*Process, error) {
|
||||||
procs, err := processes()
|
return p.ChildrenWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ChildrenWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
var dst []Win32_Process
|
||||||
|
query := wmi.CreateQuery(&dst, fmt.Sprintf("Where ParentProcessId = %d", p.Pid))
|
||||||
|
err := common.WMIQueryWithContext(ctx, query, &dst)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
out := []*Process{}
|
|
||||||
|
|
||||||
for _, proc := range procs {
|
out := []*Process{}
|
||||||
parent, err := proc.Parent()
|
for _, proc := range dst {
|
||||||
|
p, err := NewProcess(int32(proc.ProcessID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
out = append(out, p)
|
||||||
|
}
|
||||||
|
|
||||||
if parent.Pid == p.Pid {
|
|
||||||
out = append(out, proc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
func (p *Process) OpenFiles() ([]OpenFilesStat, error) {
|
||||||
|
return p.OpenFilesWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) OpenFilesWithContext(ctx context.Context) ([]OpenFilesStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
func (p *Process) Connections() ([]net.ConnectionStat, error) {
|
||||||
|
return p.ConnectionsWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ConnectionsWithContext(ctx context.Context) ([]net.ConnectionStat, error) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) NetIOCounters(pernic bool) ([]net.IOCountersStat, error) {
|
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) {
|
||||||
return nil, common.ErrNotImplementedError
|
return nil, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) IsRunning() (bool, error) {
|
func (p *Process) IsRunning() (bool, error) {
|
||||||
|
return p.IsRunningWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) IsRunningWithContext(ctx context.Context) (bool, error) {
|
||||||
return true, common.ErrNotImplementedError
|
return true, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) MemoryMaps(grouped bool) (*[]MemoryMapsStat, error) {
|
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) {
|
||||||
var ret []MemoryMapsStat
|
var ret []MemoryMapsStat
|
||||||
return &ret, common.ErrNotImplementedError
|
return &ret, common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
@ -343,17 +520,33 @@ func NewProcess(pid int32) (*Process, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) SendSignal(sig windows.Signal) error {
|
func (p *Process) SendSignal(sig windows.Signal) error {
|
||||||
|
return p.SendSignalWithContext(context.Background(), sig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SendSignalWithContext(ctx context.Context, sig windows.Signal) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Suspend() error {
|
func (p *Process) Suspend() error {
|
||||||
|
return p.SuspendWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) SuspendWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
func (p *Process) Resume() error {
|
func (p *Process) Resume() error {
|
||||||
|
return p.ResumeWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) ResumeWithContext(ctx context.Context) error {
|
||||||
return common.ErrNotImplementedError
|
return common.ErrNotImplementedError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Terminate() error {
|
func (p *Process) Terminate() error {
|
||||||
|
return p.TerminateWithContext(context.Background())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Process) TerminateWithContext(ctx context.Context) error {
|
||||||
// PROCESS_TERMINATE = 0x0001
|
// PROCESS_TERMINATE = 0x0001
|
||||||
proc := w32.OpenProcess(0x0001, false, uint32(p.Pid))
|
proc := w32.OpenProcess(0x0001, false, uint32(p.Pid))
|
||||||
ret := w32.TerminateProcess(proc, 0)
|
ret := w32.TerminateProcess(proc, 0)
|
||||||
|
@ -367,10 +560,15 @@ func (p *Process) Terminate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) Kill() error {
|
func (p *Process) Kill() error {
|
||||||
return common.ErrNotImplementedError
|
return p.KillWithContext(context.Background())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
|
func (p *Process) KillWithContext(ctx context.Context) error {
|
||||||
|
process := os.Process{Pid: int(p.Pid)}
|
||||||
|
return process.Kill()
|
||||||
|
}
|
||||||
|
|
||||||
|
func getFromSnapProcess(pid int32) (int32, int32, string, error) {
|
||||||
snap := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPPROCESS, uint32(pid))
|
snap := w32.CreateToolhelp32Snapshot(w32.TH32CS_SNAPPROCESS, uint32(pid))
|
||||||
if snap == 0 {
|
if snap == 0 {
|
||||||
return 0, 0, "", windows.GetLastError()
|
return 0, 0, "", windows.GetLastError()
|
||||||
|
@ -397,20 +595,19 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get processes
|
// Get processes
|
||||||
func processes() ([]*Process, error) {
|
func Processes() ([]*Process, error) {
|
||||||
var dst []Win32_Process
|
return ProcessesWithContext(context.Background())
|
||||||
q := wmi.CreateQuery(&dst, "")
|
|
||||||
err := wmi.Query(q, &dst)
|
|
||||||
if err != nil {
|
|
||||||
return []*Process{}, err
|
|
||||||
}
|
}
|
||||||
if len(dst) == 0 {
|
|
||||||
return []*Process{}, fmt.Errorf("could not get Process")
|
func ProcessesWithContext(ctx context.Context) ([]*Process, error) {
|
||||||
|
pids, err := Pids()
|
||||||
|
if err != nil {
|
||||||
|
return []*Process{}, fmt.Errorf("could not get Processes %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
results := []*Process{}
|
results := []*Process{}
|
||||||
for _, proc := range dst {
|
for _, pid := range pids {
|
||||||
p, err := NewProcess(int32(proc.ProcessID))
|
p, err := NewProcess(int32(pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -480,3 +677,31 @@ func getProcessMemoryInfo(h windows.Handle, mem *PROCESS_MEMORY_COUNTERS) (err e
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SYSTEM_TIMES struct {
|
||||||
|
CreateTime syscall.Filetime
|
||||||
|
ExitTime syscall.Filetime
|
||||||
|
KernelTime syscall.Filetime
|
||||||
|
UserTime syscall.Filetime
|
||||||
|
}
|
||||||
|
|
||||||
|
func getProcessCPUTimes(pid int32) (SYSTEM_TIMES, error) {
|
||||||
|
var times SYSTEM_TIMES
|
||||||
|
|
||||||
|
// PROCESS_QUERY_LIMITED_INFORMATION is 0x1000
|
||||||
|
h, err := windows.OpenProcess(0x1000, false, uint32(pid))
|
||||||
|
if err != nil {
|
||||||
|
return times, err
|
||||||
|
}
|
||||||
|
defer windows.CloseHandle(h)
|
||||||
|
|
||||||
|
err = syscall.GetProcessTimes(
|
||||||
|
syscall.Handle(h),
|
||||||
|
×.CreateTime,
|
||||||
|
×.ExitTime,
|
||||||
|
×.KernelTime,
|
||||||
|
×.UserTime,
|
||||||
|
)
|
||||||
|
|
||||||
|
return times, err
|
||||||
|
}
|
||||||
|
|
160
vendor/github.com/shirou/gopsutil/process/types_darwin.go
generated
vendored
160
vendor/github.com/shirou/gopsutil/process/types_darwin.go
generated
vendored
|
@ -1,160 +0,0 @@
|
||||||
// Copyright 2009 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// Hand Writing
|
|
||||||
// - all pointer in ExternProc to uint64
|
|
||||||
|
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input to cgo -godefs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// +godefs map struct_in_addr [4]byte /* in_addr */
|
|
||||||
// +godefs map struct_in6_addr [16]byte /* in6_addr */
|
|
||||||
// +godefs map struct_ [16]byte /* in6_addr */
|
|
||||||
|
|
||||||
package process
|
|
||||||
|
|
||||||
/*
|
|
||||||
#define __DARWIN_UNIX03 0
|
|
||||||
#define KERNEL
|
|
||||||
#define _DARWIN_USE_64_BIT_INODE
|
|
||||||
#include <dirent.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <termios.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <mach/mach.h>
|
|
||||||
#include <mach/message.h>
|
|
||||||
#include <sys/event.h>
|
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <sys/mount.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <sys/ptrace.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/signal.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/uio.h>
|
|
||||||
#include <sys/un.h>
|
|
||||||
#include <net/bpf.h>
|
|
||||||
#include <net/if_dl.h>
|
|
||||||
#include <net/if_var.h>
|
|
||||||
#include <net/route.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <sys/ucred.h>
|
|
||||||
#include <sys/proc.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/_types/_timeval.h>
|
|
||||||
#include <sys/appleapiopts.h>
|
|
||||||
#include <sys/cdefs.h>
|
|
||||||
#include <sys/param.h>
|
|
||||||
#include <bsm/audit.h>
|
|
||||||
#include <sys/queue.h>
|
|
||||||
|
|
||||||
enum {
|
|
||||||
sizeofPtr = sizeof(void*),
|
|
||||||
};
|
|
||||||
|
|
||||||
union sockaddr_all {
|
|
||||||
struct sockaddr s1; // this one gets used for fields
|
|
||||||
struct sockaddr_in s2; // these pad it out
|
|
||||||
struct sockaddr_in6 s3;
|
|
||||||
struct sockaddr_un s4;
|
|
||||||
struct sockaddr_dl s5;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct sockaddr_any {
|
|
||||||
struct sockaddr addr;
|
|
||||||
char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)];
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ucred_queue {
|
|
||||||
struct ucred *tqe_next;
|
|
||||||
struct ucred **tqe_prev;
|
|
||||||
TRACEBUF
|
|
||||||
};
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Machine characteristics; for internal use.
|
|
||||||
|
|
||||||
const (
|
|
||||||
sizeofPtr = C.sizeofPtr
|
|
||||||
sizeofShort = C.sizeof_short
|
|
||||||
sizeofInt = C.sizeof_int
|
|
||||||
sizeofLong = C.sizeof_long
|
|
||||||
sizeofLongLong = C.sizeof_longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
// Basic types
|
|
||||||
|
|
||||||
type (
|
|
||||||
_C_short C.short
|
|
||||||
_C_int C.int
|
|
||||||
_C_long C.long
|
|
||||||
_C_long_long C.longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
// Time
|
|
||||||
|
|
||||||
type Timespec C.struct_timespec
|
|
||||||
|
|
||||||
type Timeval C.struct_timeval
|
|
||||||
|
|
||||||
// Processes
|
|
||||||
|
|
||||||
type Rusage C.struct_rusage
|
|
||||||
|
|
||||||
type Rlimit C.struct_rlimit
|
|
||||||
|
|
||||||
type UGid_t C.gid_t
|
|
||||||
|
|
||||||
type KinfoProc C.struct_kinfo_proc
|
|
||||||
|
|
||||||
type Eproc C.struct_eproc
|
|
||||||
|
|
||||||
type Proc C.struct_proc
|
|
||||||
|
|
||||||
type Session C.struct_session
|
|
||||||
|
|
||||||
type ucred C.struct_ucred
|
|
||||||
|
|
||||||
type Uucred C.struct__ucred
|
|
||||||
|
|
||||||
type Upcred C.struct__pcred
|
|
||||||
|
|
||||||
type Vmspace C.struct_vmspace
|
|
||||||
|
|
||||||
type Sigacts C.struct_sigacts
|
|
||||||
|
|
||||||
type ExternProc C.struct_extern_proc
|
|
||||||
|
|
||||||
type Itimerval C.struct_itimerval
|
|
||||||
|
|
||||||
type Vnode C.struct_vnode
|
|
||||||
|
|
||||||
type Pgrp C.struct_pgrp
|
|
||||||
|
|
||||||
type UserStruct C.struct_user
|
|
||||||
|
|
||||||
type Au_session C.struct_au_session
|
|
||||||
|
|
||||||
type Posix_cred C.struct_posix_cred
|
|
||||||
|
|
||||||
type Label C.struct_label
|
|
||||||
|
|
||||||
type AuditinfoAddr C.struct_auditinfo_addr
|
|
||||||
type AuMask C.struct_au_mask
|
|
||||||
type AuTidAddr C.struct_au_tid_addr
|
|
||||||
|
|
||||||
// TAILQ(ucred)
|
|
||||||
type UcredQueue C.struct_ucred_queue
|
|
95
vendor/github.com/shirou/gopsutil/process/types_freebsd.go
generated
vendored
95
vendor/github.com/shirou/gopsutil/process/types_freebsd.go
generated
vendored
|
@ -1,95 +0,0 @@
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
// We still need editing by hands.
|
|
||||||
// go tool cgo -godefs types_freebsd.go | sed 's/\*int64/int64/' | sed 's/\*byte/int64/' > process_freebsd_amd64.go
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input to cgo -godefs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// +godefs map struct_pargs int64 /* pargs */
|
|
||||||
// +godefs map struct_proc int64 /* proc */
|
|
||||||
// +godefs map struct_user int64 /* user */
|
|
||||||
// +godefs map struct_vnode int64 /* vnode */
|
|
||||||
// +godefs map struct_vnode int64 /* vnode */
|
|
||||||
// +godefs map struct_filedesc int64 /* filedesc */
|
|
||||||
// +godefs map struct_vmspace int64 /* vmspace */
|
|
||||||
// +godefs map struct_pcb int64 /* pcb */
|
|
||||||
// +godefs map struct_thread int64 /* thread */
|
|
||||||
// +godefs map struct___sigset [16]byte /* sigset */
|
|
||||||
|
|
||||||
package process
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/user.h>
|
|
||||||
|
|
||||||
enum {
|
|
||||||
sizeofPtr = sizeof(void*),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Machine characteristics; for internal use.
|
|
||||||
|
|
||||||
const (
|
|
||||||
CTLKern = 1 // "high kernel": proc, limits
|
|
||||||
KernProc = 14 // struct: process entries
|
|
||||||
KernProcPID = 1 // by process id
|
|
||||||
KernProcProc = 8 // only return procs
|
|
||||||
KernProcPathname = 12 // path to executable
|
|
||||||
KernProcArgs = 7 // get/set arguments/proctitle
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sizeofPtr = C.sizeofPtr
|
|
||||||
sizeofShort = C.sizeof_short
|
|
||||||
sizeofInt = C.sizeof_int
|
|
||||||
sizeofLong = C.sizeof_long
|
|
||||||
sizeofLongLong = C.sizeof_longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sizeOfKinfoVmentry = C.sizeof_struct_kinfo_vmentry
|
|
||||||
sizeOfKinfoProc = C.sizeof_struct_kinfo_proc
|
|
||||||
)
|
|
||||||
|
|
||||||
// from sys/proc.h
|
|
||||||
const (
|
|
||||||
SIDL = 1 /* Process being created by fork. */
|
|
||||||
SRUN = 2 /* Currently runnable. */
|
|
||||||
SSLEEP = 3 /* Sleeping on an address. */
|
|
||||||
SSTOP = 4 /* Process debugging or suspension. */
|
|
||||||
SZOMB = 5 /* Awaiting collection by parent. */
|
|
||||||
SWAIT = 6 /* Waiting for interrupt. */
|
|
||||||
SLOCK = 7 /* Blocked on a lock. */
|
|
||||||
)
|
|
||||||
|
|
||||||
// Basic types
|
|
||||||
|
|
||||||
type (
|
|
||||||
_C_short C.short
|
|
||||||
_C_int C.int
|
|
||||||
_C_long C.long
|
|
||||||
_C_long_long C.longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
// Time
|
|
||||||
|
|
||||||
type Timespec C.struct_timespec
|
|
||||||
|
|
||||||
type Timeval C.struct_timeval
|
|
||||||
|
|
||||||
// Processes
|
|
||||||
|
|
||||||
type Rusage C.struct_rusage
|
|
||||||
|
|
||||||
type Rlimit C.struct_rlimit
|
|
||||||
|
|
||||||
type KinfoProc C.struct_kinfo_proc
|
|
||||||
|
|
||||||
type Priority C.struct_priority
|
|
||||||
|
|
||||||
type KinfoVmentry C.struct_kinfo_vmentry
|
|
103
vendor/github.com/shirou/gopsutil/process/types_openbsd.go
generated
vendored
103
vendor/github.com/shirou/gopsutil/process/types_openbsd.go
generated
vendored
|
@ -1,103 +0,0 @@
|
||||||
// +build ignore
|
|
||||||
|
|
||||||
// We still need editing by hands.
|
|
||||||
// go tool cgo -godefs types_openbsd.go | sed 's/\*int64/int64/' | sed 's/\*byte/int64/' > process_openbsd_amd64.go
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input to cgo -godefs.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// +godefs map struct_pargs int64 /* pargs */
|
|
||||||
// +godefs map struct_proc int64 /* proc */
|
|
||||||
// +godefs map struct_user int64 /* user */
|
|
||||||
// +godefs map struct_vnode int64 /* vnode */
|
|
||||||
// +godefs map struct_vnode int64 /* vnode */
|
|
||||||
// +godefs map struct_filedesc int64 /* filedesc */
|
|
||||||
// +godefs map struct_vmspace int64 /* vmspace */
|
|
||||||
// +godefs map struct_pcb int64 /* pcb */
|
|
||||||
// +godefs map struct_thread int64 /* thread */
|
|
||||||
// +godefs map struct___sigset [16]byte /* sigset */
|
|
||||||
|
|
||||||
package process
|
|
||||||
|
|
||||||
/*
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/sysctl.h>
|
|
||||||
#include <sys/user.h>
|
|
||||||
|
|
||||||
enum {
|
|
||||||
sizeofPtr = sizeof(void*),
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
*/
|
|
||||||
import "C"
|
|
||||||
|
|
||||||
// Machine characteristics; for internal use.
|
|
||||||
|
|
||||||
const (
|
|
||||||
CTLKern = 1 // "high kernel": proc, limits
|
|
||||||
KernProc = 66 // struct: process entries
|
|
||||||
KernProcAll = 0
|
|
||||||
KernProcPID = 1 // by process id
|
|
||||||
KernProcProc = 8 // only return procs
|
|
||||||
KernProcPathname = 12 // path to executable
|
|
||||||
KernProcArgs = 55 // get/set arguments/proctitle
|
|
||||||
KernProcArgv = 1
|
|
||||||
KernProcEnv = 3
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
ArgMax = 256 * 1024 // sys/syslimits.h:#define ARG_MAX
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sizeofPtr = C.sizeofPtr
|
|
||||||
sizeofShort = C.sizeof_short
|
|
||||||
sizeofInt = C.sizeof_int
|
|
||||||
sizeofLong = C.sizeof_long
|
|
||||||
sizeofLongLong = C.sizeof_longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
sizeOfKinfoVmentry = C.sizeof_struct_kinfo_vmentry
|
|
||||||
sizeOfKinfoProc = C.sizeof_struct_kinfo_proc
|
|
||||||
)
|
|
||||||
|
|
||||||
// from sys/proc.h
|
|
||||||
const (
|
|
||||||
SIDL = 1 /* Process being created by fork. */
|
|
||||||
SRUN = 2 /* Currently runnable. */
|
|
||||||
SSLEEP = 3 /* Sleeping on an address. */
|
|
||||||
SSTOP = 4 /* Process debugging or suspension. */
|
|
||||||
SZOMB = 5 /* Awaiting collection by parent. */
|
|
||||||
SDEAD = 6 /* Thread is almost gone */
|
|
||||||
SONPROC = 7 /* Thread is currently on a CPU. */
|
|
||||||
)
|
|
||||||
|
|
||||||
// Basic types
|
|
||||||
|
|
||||||
type (
|
|
||||||
_C_short C.short
|
|
||||||
_C_int C.int
|
|
||||||
_C_long C.long
|
|
||||||
_C_long_long C.longlong
|
|
||||||
)
|
|
||||||
|
|
||||||
// Time
|
|
||||||
|
|
||||||
type Timespec C.struct_timespec
|
|
||||||
|
|
||||||
type Timeval C.struct_timeval
|
|
||||||
|
|
||||||
// Processes
|
|
||||||
|
|
||||||
type Rusage C.struct_rusage
|
|
||||||
|
|
||||||
type Rlimit C.struct_rlimit
|
|
||||||
|
|
||||||
type KinfoProc C.struct_kinfo_proc
|
|
||||||
|
|
||||||
type Priority C.struct_priority
|
|
||||||
|
|
||||||
type KinfoVmentry C.struct_kinfo_vmentry
|
|
2
vendor/vendor.json
vendored
2
vendor/vendor.json
vendored
|
@ -229,7 +229,7 @@
|
||||||
{"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"jUWM0P4G1bHpO9CPS8gcr4rt1t0=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
{"path":"github.com/shirou/gopsutil/internal/common","checksumSHA1":"jUWM0P4G1bHpO9CPS8gcr4rt1t0=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"xIAuacHA0LNq1yM5Wd1q4lnbzxU=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
{"path":"github.com/shirou/gopsutil/mem","checksumSHA1":"xIAuacHA0LNq1yM5Wd1q4lnbzxU=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/net","checksumSHA1":"moxD+mq0dMHnbTeFyeEHK0Iq7i8=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
{"path":"github.com/shirou/gopsutil/net","checksumSHA1":"moxD+mq0dMHnbTeFyeEHK0Iq7i8=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
||||||
{"path":"github.com/shirou/gopsutil/process","checksumSHA1":"C6ybAAUmWz+PQKqJ8byV7Nj5JXQ=","revision":"1c211f0807a3436707409fa313599dd8c7a48664","revisionTime":"2017-08-17T03:45:37Z"},
|
{"path":"github.com/shirou/gopsutil/process","checksumSHA1":"Ylp6t7kozHBFREv3tBcK4B1SMI4=","revision":"12ab94e8042b4639d3cbd6bdafd0be9be8a33e88","revisionTime":"2018-02-21T07:26:18Z"},
|
||||||
{"path":"github.com/shirou/w32","checksumSHA1":"Nve7SpDmjsv6+rhkXAkfg/UQx94=","revision":"bb4de0191aa41b5507caa14b0650cdbddcd9280b","revisionTime":"2016-09-30T03:27:40Z"},
|
{"path":"github.com/shirou/w32","checksumSHA1":"Nve7SpDmjsv6+rhkXAkfg/UQx94=","revision":"bb4de0191aa41b5507caa14b0650cdbddcd9280b","revisionTime":"2016-09-30T03:27:40Z"},
|
||||||
{"path":"github.com/skratchdot/open-golang/open","checksumSHA1":"h/HMhokbQHTdLUbruoBBTee+NYw=","revision":"75fb7ed4208cf72d323d7d02fd1a5964a7a9073c","revisionTime":"2016-03-02T14:40:31Z"},
|
{"path":"github.com/skratchdot/open-golang/open","checksumSHA1":"h/HMhokbQHTdLUbruoBBTee+NYw=","revision":"75fb7ed4208cf72d323d7d02fd1a5964a7a9073c","revisionTime":"2016-03-02T14:40:31Z"},
|
||||||
{"path":"github.com/spf13/pflag","checksumSHA1":"Q52Y7t0lEtk/wcDn5q7tS7B+jqs=","revision":"7aff26db30c1be810f9de5038ec5ef96ac41fd7c","revisionTime":"2017-08-24T17:57:12Z"},
|
{"path":"github.com/spf13/pflag","checksumSHA1":"Q52Y7t0lEtk/wcDn5q7tS7B+jqs=","revision":"7aff26db30c1be810f9de5038ec5ef96ac41fd7c","revisionTime":"2017-08-24T17:57:12Z"},
|
||||||
|
|
Loading…
Reference in a new issue