|
|
|
package process
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Process struct {
|
|
|
|
Pid int32 `json:"pid"`
|
|
|
|
name string
|
|
|
|
status string
|
|
|
|
numCtxSwitches *NumCtxSwitchesStat
|
|
|
|
uids []int32
|
|
|
|
gids []int32
|
|
|
|
numThreads int32
|
|
|
|
memInfo *MemoryInfoStat
|
|
|
|
}
|
|
|
|
|
|
|
|
type OpenFilesStat struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Fd uint64 `json:"fd"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type MemoryInfoStat struct {
|
|
|
|
RSS uint64 `json:"rss"` // bytes
|
|
|
|
VMS uint64 `json:"vms"` // bytes
|
|
|
|
Swap uint64 `json:"swap"` // bytes
|
|
|
|
}
|
|
|
|
|
|
|
|
type RlimitStat struct {
|
|
|
|
Resource int32 `json:"resource"`
|
|
|
|
Soft int32 `json:"soft"`
|
|
|
|
Hard int32 `json:"hard"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type IOCountersStat struct {
|
|
|
|
ReadCount uint64 `json:"read_count"`
|
|
|
|
WriteCount uint64 `json:"write_count"`
|
|
|
|
ReadBytes uint64 `json:"read_bytes"`
|
|
|
|
WriteBytes uint64 `json:"write_bytes"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type NumCtxSwitchesStat struct {
|
|
|
|
Voluntary int64 `json:"voluntary"`
|
|
|
|
Involuntary int64 `json:"involuntary"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p Process) String() string {
|
|
|
|
s, _ := json.Marshal(p)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (o OpenFilesStat) String() string {
|
|
|
|
s, _ := json.Marshal(o)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m MemoryInfoStat) String() string {
|
|
|
|
s, _ := json.Marshal(m)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r RlimitStat) String() string {
|
|
|
|
s, _ := json.Marshal(r)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (i IOCountersStat) String() string {
|
|
|
|
s, _ := json.Marshal(i)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p NumCtxSwitchesStat) String() string {
|
|
|
|
s, _ := json.Marshal(p)
|
|
|
|
return string(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func PidExists(pid int32) (bool, error) {
|
|
|
|
pids, err := Pids()
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, i := range pids {
|
|
|
|
if i == pid {
|
|
|
|
return true, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false, err
|
|
|
|
}
|