提交 c6c910cc 编写于 作者: T Tom Barker

Add additional process states.

上级 78065a7c
......@@ -45,13 +45,30 @@ type Process struct {
// Process status
const (
// Running marks a task a running or runnable (on the run queue)
Running = "running"
Sleep = "sleep"
Stop = "stop"
Idle = "idle"
Zombie = "zombie"
Wait = "wait"
Lock = "lock"
// 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"
// Wait marks an idle interrupt thread (or paging in pre 2.6.xx Linux)
Wait = "wait"
// 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
}
}
......@@ -660,7 +660,11 @@ func Test_CPUTimes(t *testing.T) {
func Test_OpenFiles(t *testing.T) {
fp, err := os.Open("process_test.go")
defer fp.Close()
assert.Nil(t, err)
defer func() {
err := fp.Close()
assert.Nil(t, err)
}()
pid := os.Getpid()
p, err := NewProcess(int32(pid))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册