proc

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPIDs

func GetPIDs() ([]string, error)

GetPIDs extracts and returns all PIDs from /proc.

func GetPIDsFromCgroup

func GetPIDsFromCgroup(pid string) ([]string, error)

GetPIDsFromCgroup returns a strings slice of all pids listesd in pid's pids cgroup. It auto-detects if we're running in unified mode, or not.

func ParseAttrCurrent

func ParseAttrCurrent(pid string) (string, error)

ParseAttrCurrent returns the contents of /proc/$pid/attr/current of "?" if labeling is not supported on the host.

func ParseCmdLine

func ParseCmdLine(pid string) ([]string, error)

ParseCmdLine parses a /proc/$pid/cmdline file and returns a string slice.

func ParsePIDNamespace

func ParsePIDNamespace(pid string) (string, error)

ParsePIDNamespace returns the content of /proc/$pid/ns/pid.

func ParseUserNamespace

func ParseUserNamespace(pid string) (string, error)

ParseUserNamespace returns the content of /proc/$pid/ns/user.

Types

type IDMap

type IDMap struct {
	ContainerID int
	HostID      int
	Size        int
}

IDMap ...

func ReadMappings

func ReadMappings(path string) ([]IDMap, error)

ReadMappings reads the user namespace mappings at the specified path

type Stat

type Stat struct {
	// (1) The process ID
	Pid string
	// (2) The filename of the executable, in parentheses. This is visible
	// whether or not the executable is swapped out.
	Comm string
	// (3) The process state (e.g., running, sleeping, zombie, dead).
	// Refer to proc(5) for further details.
	State string
	// (4) The PID of the parent of this process.
	Ppid string
	// (5) The process group ID of the process.
	Pgrp string
	// (6) The session ID of the process.
	Session string
	// (7) The controlling terminal of the process. (The minor device
	// number is contained in the combination of bits 31 to 20 and 7 to 0;
	// the major device number is in bits 15 to 8.)
	TtyNr string
	// (8) The ID of the foreground process group of the controlling
	// terminal of the process.
	Tpgid string
	// (9) The kernel flags word of the process. For bit meanings, see the
	// PF_* defines in the Linux kernel source file
	// include/linux/sched.h. Details depend on the kernel version.
	Flags string
	// (10) The number of minor faults the process has made which have not
	// required loading a memory page from disk.
	Minflt string
	// (11) The number of minor faults that the process's waited-for
	// children have made.
	Cminflt string
	// (12) The number of major faults the process has made which have
	// required loading a memory page from disk.
	Majflt string
	// (13) The number of major faults that the process's waited-for
	// children have made.
	Cmajflt string
	// (14) Amount of time that this process has been scheduled in user
	// mode, measured in clock ticks (divide by
	// sysconf(_SC_CLK_TCK)). This includes guest time, guest_time
	// (time spent running a virtual CPU, see below), so that applications
	// that are not aware of the guest time field do not lose that time
	// from their calculations.
	Utime string
	// (15) Amount of time that this process has been scheduled in kernel
	// mode, measured in clock ticks (divide by sysconf(_SC_CLK_TCK)).
	Stime string
	// (16) Amount of time that this process's waited-for children have
	// been scheduled in user mode, measured in clock ticks (divide by
	// sysconf(_SC_CLK_TCK)). (See also times(2).) This includes guest
	// time, cguest_time (time spent running a virtual CPU, see below).
	Cutime string
	// (17) Amount of time that this process's waited-for children have
	// been scheduled in kernel mode, measured in clock ticks (divide by
	// sysconf(_SC_CLK_TCK)).
	Cstime string
	// (18) (Explanation for Linux 2.6+) For processes running a real-time
	// scheduling policy (policy below; see sched_setscheduler(2)), this is
	// the negated scheduling pri- ority, minus one; that is, a number
	// in the range -2 to -100, corresponding to real-time priorities 1 to
	// 99. For processes running under a non-real-time scheduling
	// policy, this is the raw nice value (setpriority(2)) as represented
	// in the kernel. The kernel stores nice values as numbers in the
	// range 0 (high) to 39 (low), corresponding to the user-visible nice
	// range of -20 to 19.
	Priority string
	// (19) The nice value (see setpriority(2)), a value in the range 19
	// (low priority) to -20 (high priority).
	Nice string
	// (20) Number of threads in this process (since Linux 2.6). Before
	// kernel 2.6, this field was hard coded to 0 as a placeholder for an
	// earlier removed field.
	NumThreads string
	// (21) The time in jiffies before the next SIGALRM is sent to the
	// process due to an interval timer. Since kernel 2.6.17, this
	// field is no longer maintained, and is hard coded as 0.
	Itrealvalue string
	// (22) The time the process started after system boot. In kernels
	// before Linux 2.6, this value was expressed in jiffies. Since
	// Linux 2.6, the value is expressed in clock ticks (divide by
	// sysconf(_SC_CLK_TCK)).
	Starttime string
	// (23) Virtual memory size in bytes.
	Vsize string
}

Stat is a direct translation of a `/proc/[pid]/stat` file as described in the proc(5) manpage. Please note that it is not a full translation as not all fields are in the scope of this library and higher indices are Kernel-version dependent.

func ParseStat

func ParseStat(pid string) (*Stat, error)

ParseStat parses the /proc/$pid/stat file and returns a Stat.

type Status

type Status struct {
	// Name: Command run by this process.
	Name string
	// Umask: Process umask, expressed in octal with a leading  zero;  see
	// umask(2). (Since Linux 4.7.)
	Umask string
	// State:  Current  state  of the process.  One of "R (running)", "S
	// (sleeping)", "D (disk sleep)", "T (stopped)", "T (tracing stop)", "Z
	// (zombie)", or "X (dead)".
	State string
	// Tgid: Thread group ID (i.e., Process ID).
	Tgid string
	// Ngid: NUMA group ID (0 if none; since Linux 3.13).
	Ngid string
	// Pid: Thread ID (see gettid(2)).
	Pid string
	// PPid: PID of parent process.
	PPid string
	// TracerPid: PID of process tracing this process (0 if not being
	// traced).
	TracerPid string
	// Uids: Real, effective, saved set, and filesystem.
	Uids []string
	// Gids: Real, effective, saved set, and filesystem.
	Gids []string
	// FDSize: Number of file descriptor slots currently allocated.
	FdSize string
	// Groups: Supplementary group list.
	Groups []string
	// NStgid : Thread group ID (i.e., PID) in each of the PID namespaces
	// of which [pid] is  a member.   The  leftmost  entry shows the value
	// with respect to the PID namespace of the reading process, followed
	// by the value in successively nested inner namespaces.  (Since Linux
	// 4.1.)
	NStgid string
	// NSpid:  Thread ID in each of the PID namespaces of which [pid] is a
	// member.  The fields are ordered as for NStgid.  (Since Linux 4.1.)
	NSpid []string
	// NSpgid: Process group ID in each of the PID namespaces of which
	// [pid] is a member.  The fields are ordered as for NStgid.  (Since
	// Linux 4.1.)
	NSpgid string
	// NSsid:  descendant  namespace session ID hierarchy Session ID in
	// each of the PID names- paces of which [pid] is a member.  The fields
	// are ordered as for NStgid.  (Since  Linux 4.1.)
	NSsid string
	// VMPeak: Peak virtual memory size.
	VMPeak string
	// VMSize: Virtual memory size.
	VMSize string
	// VMLck: Locked memory size (see mlock(3)).
	VMLCK string
	// VMPin:  Pinned  memory  size  (since  Linux  3.2).  These are pages
	// that can't be moved because something needs to directly access
	// physical memory.
	VMPin string
	// VMHWM: Peak resident set size ("high water mark").
	VMHWM string
	// VMRSS: Resident set size.  Note that the value here is the sum of
	// RssAnon, RssFile, and RssShmem.
	VMRSS string
	// RssAnon: Size of resident anonymous memory.  (since Linux 4.5).
	RssAnon string
	// RssFile: Size of resident file mappings.  (since Linux 4.5).
	RssFile string
	// RssShmem:  Size  of  resident  shared memory (includes System V
	// shared memory, mappings from tmpfs(5), and shared anonymous
	// mappings).  (since Linux 4.5).
	RssShmem string
	// VMData: Size of data segment.
	VMData string
	// VMStk: Size of stack segment.
	VMStk string
	// VMExe: Size of text segment.
	VMExe string
	// VMLib: Shared library code size.
	VMLib string
	// VMPTE: Page table entries size (since Linux 2.6.10).
	VMPTE string
	// VMPMD: Size of second-level page tables (since Linux 4.0).
	VMPMD string
	// VMSwap: Swapped-out virtual memory size by anonymous private pages;
	// shmem swap usage is not included (since Linux 2.6.34).
	VMSwap string
	// HugetlbPages: Size of hugetlb memory portions.  (since Linux 4.4).
	HugetlbPages string
	// Threads: Number of threads in process containing this thread.
	Threads string
	// SigQ: This field contains two slash-separated numbers that relate to
	// queued signals for the real user ID of this process.  The first of
	// these is the number of currently queued signals  for  this  real
	// user ID, and the second is the resource limit on the number of
	// queued signals for this process (see the  description  of
	// RLIMIT_SIGPENDING  in  getr- limit(2)).
	SigQ string
	// SigPnd:  Number  of signals pending for thread and for (see
	// pthreads(7)).
	SigPnd string
	// ShdPnd:  Number  of signals pending for process as a whole (see
	// signal(7)).
	ShdPnd string
	//  SigBlk: Mask indicating signals being  blocked (see signal(7)).
	SigBlk string
	//  SigIgn: Mask indicating signals being ignored (see signal(7)).
	SigIgn string
	// SigCgt: Mask indicating signals being  blocked caught (see signal(7)).
	SigCgt string
	// CapInh:  Mask of capabilities enabled in inheritable sets (see
	// capabilities(7)).
	CapInh string
	// CapPrm:  Mask of capabilities enabled in permitted sets (see
	// capabilities(7)).
	CapPrm string
	// CapEff:  Mask of capabilities enabled in effective sets (see
	// capabilities(7)).
	CapEff string
	// CapBnd: Capability Bounding set (since Linux 2.6.26, see
	// capabilities(7)).
	CapBnd string
	// CapAmb: Ambient capability set (since Linux 4.3, see capabilities(7)).
	CapAmb string
	// NoNewPrivs: Value of the no_new_privs bit (since Linux 4.10, see
	// prctl(2)).
	NoNewPrivs string
	// Seccomp: Seccomp mode of the process (since Linux 3.8, see
	// seccomp(2)).  0  means  SEC- COMP_MODE_DISABLED;  1  means
	// SECCOMP_MODE_STRICT;  2 means SECCOMP_MODE_FILTER.  This field is
	// provided only if the kernel was built with the CONFIG_SECCOMP kernel
	// configu- ration option enabled.
	Seccomp string
	// Cpus_allowed:  Mask  of  CPUs  on  which  this process may run
	// (since Linux 2.6.24, see cpuset(7)).
	CpusAllowed string
	// Cpus_allowed_list: Same as previous, but in "list  format"  (since
	// Linux  2.6.26,  see cpuset(7)).
	CpusAllowedList string
	// Mems_allowed:  Mask  of  memory  nodes allowed to this process
	// (since Linux 2.6.24, see cpuset(7)).
	MemsAllowed string
	// Mems_allowed_list: Same as previous, but in "list  format"  (since
	// Linux  2.6.26,  see cpuset(7)).
	MemsAllowedList string
	// voluntaryCtxtSwitches:  Number of voluntary context switches
	// (since Linux 2.6.23).
	VoluntaryCtxtSwitches string
	// nonvoluntaryCtxtSwitches:  Number of involuntary context switches
	// (since Linux 2.6.23).
	NonvoluntaryCtxtSwitches string
}

Status is a direct translation of a `/proc/[pid]/status`, which provides much of the information in /proc/[pid]/stat and /proc/[pid]/statm in a format that's easier for humans to parse.

func ParseStatus

func ParseStatus(pid string, joinUserNS bool) (*Status, error)

ParseStatus parses the /proc/$pid/status file and returns a *Status.

Jump to

Keyboard shortcuts

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