[process]linux: update comment to show godoc.org.

pull/189/head
Shirou WAKAYAMA 9 years ago
parent bd1b04fe67
commit 860f5a0803

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

Loading…
Cancel
Save