Documentation
¶
Overview ¶
Package process provides methods for getting information about active processes
Example (CalculateCPUUsage) ¶
pid := 1345 duration := time.Second * 15 sample1, _ := GetSample(pid) time.Sleep(duration) sample2, _ := GetSample(pid) fmt.Printf("CPU Usage: %g%%\n", CalculateCPUUsage(sample1, sample2, duration))
Output:
Example (GetList) ¶
processes, err := GetList() if err != nil { return } // processes is slice with info about all active processes fmt.Println(processes)
Output:
Example (GetTree) ¶
process, err := GetTree() if err != nil { return } // process is a top process in the tree fmt.Println(process.PID)
Output:
Index ¶
Examples ¶
Constants ¶
View Source
const ( STATE_RUNNING = "R" STATE_SLEEPING = "S" STATE_DISK_WAIT = "D" STATE_ZOMBIE = "Z" STATE_STOPPED = "T" STATE_DEAD = "X" STATE_WAKEKILL = "K" STATE_WAKING = "W" STATE_PARKED = "P" )
Process state flags
Variables ¶
This section is empty.
Functions ¶
func CalculateCPUUsage ¶
func CalculateCPUUsage(s1, s2 ProcSample, duration time.Duration) float64
CalculateCPUUsage calculates CPU usage
Types ¶
type MemInfo ¶
type MemInfo struct { VmPeak uint64 `json:"peak"` // Peak virtual memory size VmSize uint64 `json:"size"` // Virtual memory size VmLck uint64 `json:"lck"` // Locked memory size VmPin uint64 `json:"pin"` // Pinned memory size (since Linux 3.2) VmHWM uint64 `json:"hwm"` // Peak resident set size ("high water mark") VmRSS uint64 `json:"rss"` // Resident set size VmData uint64 `json:"data"` // Size of data VmStk uint64 `json:"stk"` // Size of stack VmExe uint64 `json:"exe"` // Size of text segments VmLib uint64 `json:"lib"` // Shared library code size VmPTE uint64 `json:"pte"` // Page table entries size (since Linux 2.6.10) VmSwap uint64 `json:"swap"` // Swap size }
MemInfo contains process memory usage stats
func GetMemInfo ¶
GetMemInfo returns info about process memory usage
type ProcInfo ¶
type ProcInfo struct { PID int `json:"pid"` // The process ID Comm string `json:"comm"` // The filename of the executable, in parentheses State string `json:"state"` // Process state PPID int `json:"ppid"` // The PID of the parent of this process Session int `json:"session"` // The session ID of the process TTYNR int `json:"tty_nr"` // The controlling terminal of the process TPGid int `json:"tpgid"` // The ID of the foreground process group of the controlling terminal of the process UTime uint64 `json:"utime"` // Amount of time that this process has been scheduled in user mode, measured in clock ticks STime uint64 `json:"stime"` // Amount of time that this process has been scheduled in kernel mode, measured in clock ticks CUTime uint64 `json:"cutime"` // Amount of time that this process's waited-for children have been scheduled in user mode, measured in clock ticks CSTime uint64 `json:"cstime"` // Amount of time that this process's waited-for children have been scheduled in kernel mode, measured in clock ticks Priority int `json:"priority"` // Priority Nice int `json:"nice"` // The nice value NumThreads int `json:"num_threads"` // Number of threads in this process }
ProcInfo contains partial info from /proc/[PID]/stat
func (*ProcInfo) ToSample ¶
func (pi *ProcInfo) ToSample() ProcSample
ToSample converts ProcInfo to ProcSample for CPU usage calculation
type ProcSample ¶
type ProcSample uint
ProcSample contains value for usage calculation
func GetSample ¶
func GetSample(pid int) (ProcSample, error)
GetSample returns ProcSample for CPU usage calculation
type ProcessInfo ¶
type ProcessInfo struct { Command string // Full command User string // Username PID int // PID IsThread bool // True if process is thread Parent int // Parent process PID Childs []*ProcessInfo // Slice with child processes }
ProcessInfo contains basic info about process
func GetList ¶
func GetList() ([]*ProcessInfo, error)
GetList returns slice with all active processes on the system
func GetTree ¶
func GetTree(pid ...int) (*ProcessInfo, error)
GetTree returns root process with all subprocesses on the system
Click to show internal directories.
Click to hide internal directories.