Help us shape the future of Go! Take the 2026 Go Developer Survey

procinfo

package module
v0.0.0-...-4d0c65a Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2020 License: MIT Imports: 9 Imported by: 0

README

procinfo

Golang Linux based /proc parsing to retrieve information about processes.

Doesn't touch Windows cause that's the bad place.

Documentation

Index

Constants

View Source
const (
	ProcLockColPriority = iota
	ProcLockColType

	ProcLockColExclusive
	ProcLockColPID
	ProcLockColInode
	ProcLockColByteStart
	ProcLockColByteEnd
)
View Source
const (
	ProcStateRunning      = 'R'
	ProcStateSleeping     = 'S'
	ProcStateWaiting      = 'D'
	ProcStateZombie       = 'Z'
	ProcStateStopped      = 'T'
	ProcStateTraceStopped = 't'
	ProcStatePaging       = 'W'
	ProcStateLegacyDead   = 'X'
	ProcStateDead         = 'x'
	ProcStateWakekill     = 'K'
	ProcStateWaking       = 'W'
	ProcStateParked       = 'P'
)
View Source
const FmtProcCmdlineFile = "/proc/%d/cmdline"
View Source
const FmtProcCwdFile = "/proc/%d/cwd"
View Source
const FmtProcEnvFile = "/proc/%d/environ"
View Source
const FmtProcLocks = "%d: %s %s %s %d %x:%x:%d"
View Source
const FmtProcPidStat = "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d"

position 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

View Source
const FmtProcStatFile = "/proc/%d/stat"
View Source
const (
	ProcLock = "/proc/locks"
)

Variables

View Source
var (
	ErrPermissionDenied = errors.New("cannot read /proc/locks")
)
View Source
var FileLocks = fileLocksType{
	// contains filtered or unexported fields
}
View Source
var TestData_CheckInode_Processes = map[uint64][]Process{
	810: []Process{
		{
			Pid:          5623,
			OriginalName: "slack",
			State:        'S',
			Cwd:          "/proc/lol/fd",
			PPid:         2770,
			UserTime:     1,
			KernelTime:   286,
			Nice:         20,
			Cmdline:      []string{"/usr/lib/slack/slack"},
			Env: []string{
				"slack",
				"",
				"",
				"\n",
			},
		},
	},
	1088: []Process{
		{
			Pid:          5705,
			OriginalName: "chrome",
			State:        'S',
			Cwd:          "/proc/5715/fdinfo",
			PPid:         5680,
			UserTime:     0,
			KernelTime:   2,
			Nice:         20,
			Cmdline: []string{
				"/opt/google/chrome/chrome --type=zygote --enable-crash-reporter=4d5673fa-4274-4096-a4f8-0c3f692622fa,",
				"",
			},
			Env: []string{
				"",
				"",
				"",
				"",
				"",
				"\n",
			},
		},
	},
	23600664: []Process{
		{
			Pid:          8819,
			OriginalName: "code",
			State:        'S',
			Cwd:          "/proc/notthere",
			PPid:         1,
			UserTime:     1,
			KernelTime:   578,
			Nice:         20,
			Cmdline:      []string{"/usr/share/code/code .", ""},
			Env: []string{
				"",
				"",
				"",
				"",
				"",
				"\n",
			},
		},
	},
}
View Source
var Testdata_Lock = []Lock{
	Lock{
		Priority:  41,
		ByteRange: false,
		Exclusive: true,
		PID:       5623,
		DevMajor:  0x00,
		DevMinor:  0x17,
		Inode:     810,
	},
	Lock{
		Priority:  42,
		ByteRange: true,
		Exclusive: false,
		PID:       5705,
		DevMajor:  0x00,
		DevMinor:  0x17,
		Inode:     1088,
	},
	Lock{
		Priority:  61,
		ByteRange: false,
		Exclusive: true,
		PID:       8819,
		DevMajor:  0xfd,
		DevMinor:  0x01,
		Inode:     23600664,
	},
}

Functions

This section is empty.

Types

type Lock

type Lock struct {
	Priority  uint32 `json:"lockPriority"`
	ByteRange bool   `json:"isByteRange"`
	Exclusive bool   `json:"exclusive"`
	PID       uint32 `json:"pid"`
	DevMajor  uint16 `json:"fsMajor"`
	DevMinor  uint16 `json:"fsMinor"`
	Inode     uint64 `json:"inode"`
}

type Process

type Process struct {
	// process number and parent process number
	Pid          uint32
	PPid         uint32
	OriginalName string
	State        rune

	UserTime   uint64
	KernelTime uint64

	Nice        uint8
	MemoryUsage uint64

	Cmdline []string
	Env     []string
	Cwd     string
}

func GetProcessByPid

func GetProcessByPid(pid uint32) Process

Jump to

Keyboard shortcuts

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