linux

package
v4.7.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Unlimited uint64 = 1<<64 - 1
)

Represents Linux's unlimited for resource limits.

Variables

This section is empty.

Functions

func ReadCPUPeriod

func ReadCPUPeriod(cgroup string) (period time.Duration, err error)

ReadCPUPeriod takes a string representing a Linux cgroup and returns the period as a time.Duration that is applied for this cgroup and an error, if any.

func ReadCPUQuota

func ReadCPUQuota(cgroup string) (quota time.Duration, err error)

ReadCPUQuota takes a string representing a Linux cgroup and returns the quota as a time.Duration that is applied for this cgroup and an error, if any.

func ReadCPUShares

func ReadCPUShares(cgroup string) (shares int64, err error)

ReadCPUShares takes a string representing a Linux cgroup and returns an int64 representing the cpu shares allotted for this cgroup and an error, if any.

func ReadMemoryLimit

func ReadMemoryLimit(pid int) (limit uint64, err error)

ReadMemoryLimit returns the memory limit and an error, if any, for a PID.

func ReadOpenFileCount

func ReadOpenFileCount(pid int) (n uint64, err error)

ReadOpenFileCount takes an int representing a PID and returns a uint64 representing the open file descriptor count for this process and an error, if any.

Types

type CGroup

type CGroup struct {
	ID   int
	Name string
	Path string // Path in /sys/fs/cgroup
}

CGroup holds configuration information for a Linux cgroup.

type Limits

type Limits struct {
	Name string
	Soft uint64
	Hard uint64
	Unit string
}

Limits holds configuration for resource limits.

type ProcCGroup

type ProcCGroup []CGroup

ProcCGroup is a type alias for a []CGroup.

func ParseProcCGroup

func ParseProcCGroup(s string) (proc ProcCGroup, err error)

ParseProcCGroup parses Linux system cgroup data and returns a ProcCGroup and error, if any is encountered.

func ReadProcCGroup

func ReadProcCGroup(pid int) (proc ProcCGroup, err error)

ReadProcCGroup takes an int argument representing a PID and returns a ProcCGroup and error, if any is encountered.

func (ProcCGroup) Lookup

func (pcg ProcCGroup) Lookup(name string) (cgroup CGroup, ok bool)

Lookup takes a string argument representing the name of a Linux cgroup and returns a CGroup and bool indicating whether or not the cgroup was found.

type ProcLimits

type ProcLimits struct {
	CPUTime          Limits // seconds
	FileSize         Limits // bytes
	DataSize         Limits // bytes
	StackSize        Limits // bytes
	CoreFileSize     Limits // bytes
	ResidentSet      Limits // bytes
	Processes        Limits // processes
	OpenFiles        Limits // files
	LockedMemory     Limits // bytes
	AddressSpace     Limits // bytes
	FileLocks        Limits // locks
	PendingSignals   Limits // signals
	MsgqueueSize     Limits // bytes
	NicePriority     Limits
	RealtimePriority Limits
	RealtimeTimeout  Limits
}

ProcLimits holds Limits for processes.

func ParseProcLimits

func ParseProcLimits(s string) (proc ProcLimits, err error)

ParseProcLimits parses system process limits and returns a ProcLimits and error, if any.

func ReadProcLimits

func ReadProcLimits(pid int) (proc ProcLimits, err error)

ReadProcLimits returns the ProcLimits and an error, if any, for a PID.

type ProcSched

type ProcSched struct {
	NRSwitches            uint64 // nr_switches
	NRVoluntarySwitches   uint64 // nr_voluntary_switches
	NRInvoluntarySwitches uint64 // nr_involuntary_switches
	SEAvgLoadSum          uint64 // se.avg.load_sum
	SEAvgUtilSum          uint64 // se.avg.util_sum
	SEAvgLoadAvg          uint64 // se.avg.load_avg
	SEAvgUtilAvg          uint64 // se.avg.util_avg
}

ProcSched contains statistics about process scheduling, utilization, and switches.

func ParseProcSched

func ParseProcSched(s string) (proc ProcSched, err error)

ParseProcSched processes system process scheduling data and returns a ProcSched and error, if any.

func ReadProcSched

func ReadProcSched(pid int) (proc ProcSched, err error)

ReadProcSched returns a ProcSched and error, if any, for a PID.

type ProcStat

type ProcStat struct {
	Pid                 int32     // (1) pid
	Comm                string    // (2) comm
	State               ProcState // (3) state
	Ppid                int32     // (4) ppid
	Pgrp                int32     // (5) prgp
	Session             int32     // (6) session
	TTY                 int32     // (7) tty_nr
	Tpgid               int32     // (8) tpgid
	Flags               uint32    // (9) flags
	Minflt              uint64    // (10) minflt
	Cminflt             uint64    // (11) cminflt
	Majflt              uint64    // (12) majflt
	Cmajflt             uint64    // (13) cmajflt
	Utime               uint64    // (14) utime
	Stime               uint64    // (15) stime
	Cutime              int64     // (16) cutime
	Cstime              int64     // (17) cstime
	Priority            int64     // (18) priority
	Nice                int64     // (19) nice
	NumThreads          int64     // (20) num_threads
	Itrealvalue         int64     // (21) itrealvalue
	Starttime           uint64    // (22) starttime
	Vsize               uint64    // (23) vsize
	Rss                 uint64    // (24) rss
	Rsslim              uint64    // (25) rsslim
	Startcode           uintptr   // (26) startcode
	Endcode             uintptr   // (27) endcode
	Startstack          uintptr   // (28) startstack
	Kstkeep             uint64    // (29) kstkeep
	Kstkeip             uint64    // (30) kstkeip
	Signal              uint64    // (31) signal
	Blocked             uint64    // (32) blocked
	Sigignore           uint64    // (33) sigignore
	Sigcatch            uint64    // (34) sigcatch
	Wchan               uintptr   // (35) wchan
	Nswap               uint64    // (36) nswap
	Cnswap              uint64    // (37) cnswap
	ExitSignal          int32     // (38) exit_signal
	Processor           int32     // (39) processor
	RTPriority          uint32    // (40) rt_priority
	Policy              uint32    // (41) policy
	DelayacctBlkioTicks uint64    // (42) delayacct_blkio_ticks
	GuestTime           uint64    // (43) guest_time
	CguestTime          int64     // (44) cguest_time
	StartData           uintptr   // (45) start_data
	EndData             uintptr   // (46) end_data
	StartBrk            uintptr   // (47) start_brk
	ArgStart            uintptr   // (48) arg_start
	ArgEnd              uintptr   // (49) arg_end
	EnvStart            uintptr   // (50) env_start
	EnvEnd              uintptr   // (51) env_end
	ExitCode            int32     // (52) exit_code
}

ProcStat contains statistics associated with a process.

func ParseProcStat

func ParseProcStat(s string) (proc ProcStat, err error)

ParseProcStat parses system process statistics and returns a ProcStat and error, if any.

func ReadProcStat

func ReadProcStat(pid int) (proc ProcStat, err error)

ReadProcStat returns a ProcStat and error, if any, for a PID.

type ProcState

type ProcState rune

ProcState represents the underlying OS state of a process.

const (
	Running                         ProcState = 'R'
	Sleeping                        ProcState = 'S'
	WaitingUninterruptibleDiskSleep ProcState = 'D'
	Zombie                          ProcState = 'Z'
	Stopped                         ProcState = 'T'
	TracingStop                     ProcState = 't'
	Paging                          ProcState = 'P'
	Dead                            ProcState = 'X'
	Dead_                           ProcState = 'x'
	Wakekill                        ProcState = 'W'
	Parked                          ProcState = 'P'
)

Enumerated ProcStates.

func (*ProcState) Scan

func (ps *ProcState) Scan(s fmt.ScanState, _ rune) (err error)

Scan updates the ProcState for a process.

type ProcStatm

type ProcStatm struct {
	Size     uint64 // (1) size
	Resident uint64 // (2) resident
	Share    uint64 // (3) share
	Text     uint64 // (4) text
	Lib      uint64 // (5) lib
	Data     uint64 // (6) data
	Dt       uint64 // (7) dt
}

ProcStatm contains statistics about memory utilization of a process.

func ParseProcStatm

func ParseProcStatm(s string) (proc ProcStatm, err error)

ParseProcStatm parses system proc data and returns a ProcStatm and error, if any.

func ReadProcStatm

func ReadProcStatm(pid int) (proc ProcStatm, err error)

ReadProcStatm returns a ProcStatm and an error, if any, for a PID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL