|
|
|
@ -45,13 +45,30 @@ type Process struct {
|
|
|
|
|
|
|
|
|
|
// Process status
|
|
|
|
|
const (
|
|
|
|
|
// Running marks a task a running or runnable (on the run queue)
|
|
|
|
|
Running = "running"
|
|
|
|
|
// Blocked marks a task waiting on a short, uninterruptable operation (usually IO)
|
|
|
|
|
Blocked = "blocked"
|
|
|
|
|
// Idle marks a task sleeping for more than about 20 seconds
|
|
|
|
|
Idle = "idle"
|
|
|
|
|
// Lock marks a task waiting to acquire a lock
|
|
|
|
|
Lock = "lock"
|
|
|
|
|
// Sleep marks task waiting for short, interruptable operation
|
|
|
|
|
Sleep = "sleep"
|
|
|
|
|
// Stop marks a stopped process
|
|
|
|
|
Stop = "stop"
|
|
|
|
|
Idle = "idle"
|
|
|
|
|
Zombie = "zombie"
|
|
|
|
|
// Wait marks an idle interrupt thread (or paging in pre 2.6.xx Linux)
|
|
|
|
|
Wait = "wait"
|
|
|
|
|
Lock = "lock"
|
|
|
|
|
// Zombie marks a defunct process, terminated but not reaped by its parent
|
|
|
|
|
Zombie = "zombie"
|
|
|
|
|
|
|
|
|
|
// Solaris states. See https://github.com/collectd/collectd/blob/1da3305c10c8ff9a63081284cf3d4bb0f6daffd8/src/processes.c#L2115
|
|
|
|
|
Daemon = "daemon"
|
|
|
|
|
Detached = "detached"
|
|
|
|
|
System = "system"
|
|
|
|
|
Orphan = "orphan"
|
|
|
|
|
|
|
|
|
|
UnknownState = ""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type OpenFilesStat struct {
|
|
|
|
@ -554,23 +571,41 @@ func (p *Process) Environ() ([]string, error) {
|
|
|
|
|
return p.EnvironWithContext(context.Background())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// convertStatusChar as reported by the ps command across different platforms.
|
|
|
|
|
func convertStatusChar(letter string) string {
|
|
|
|
|
// Sources
|
|
|
|
|
// Darwin: http://www.mywebuniversity.com/Man_Pages/Darwin/man_ps.html
|
|
|
|
|
// FreeBSD: https://www.freebsd.org/cgi/man.cgi?ps
|
|
|
|
|
// Linux https://man7.org/linux/man-pages/man1/ps.1.html
|
|
|
|
|
// OpenBSD: https://man.openbsd.org/ps.1#state
|
|
|
|
|
// Solaris: https://github.com/collectd/collectd/blob/1da3305c10c8ff9a63081284cf3d4bb0f6daffd8/src/processes.c#L2115
|
|
|
|
|
switch letter {
|
|
|
|
|
case "A":
|
|
|
|
|
return Daemon
|
|
|
|
|
case "D", "U":
|
|
|
|
|
return Blocked
|
|
|
|
|
case "E":
|
|
|
|
|
return Detached
|
|
|
|
|
case "I":
|
|
|
|
|
return Idle
|
|
|
|
|
case "L":
|
|
|
|
|
return Lock
|
|
|
|
|
case "O":
|
|
|
|
|
return Orphan
|
|
|
|
|
case "R":
|
|
|
|
|
return Running
|
|
|
|
|
case "S":
|
|
|
|
|
return Sleep
|
|
|
|
|
case "T":
|
|
|
|
|
case "T", "t":
|
|
|
|
|
// "t" is used by Linux to signal stopped by the debugger during tracing
|
|
|
|
|
return Stop
|
|
|
|
|
case "I":
|
|
|
|
|
return Idle
|
|
|
|
|
case "Z":
|
|
|
|
|
return Zombie
|
|
|
|
|
case "W":
|
|
|
|
|
return Wait
|
|
|
|
|
case "L":
|
|
|
|
|
return Lock
|
|
|
|
|
case "Y":
|
|
|
|
|
return System
|
|
|
|
|
case "Z":
|
|
|
|
|
return Zombie
|
|
|
|
|
default:
|
|
|
|
|
return ""
|
|
|
|
|
return UnknownState
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|