@@ -45,13 +45,30 @@ type Process struct {
45
45
46
46
// Process status
47
47
const (
48
+ // Running marks a task a running or runnable (on the run queue)
48
49
Running = "running"
49
- Sleep = "sleep"
50
- Stop = "stop"
51
- Idle = "idle"
52
- Zombie = "zombie"
53
- Wait = "wait"
54
- Lock = "lock"
50
+ // Blocked marks a task waiting on a short, uninterruptable operation (usually IO)
51
+ Blocked = "blocked"
52
+ // Idle marks a task sleeping for more than about 20 seconds
53
+ Idle = "idle"
54
+ // Lock marks a task waiting to acquire a lock
55
+ Lock = "lock"
56
+ // Sleep marks task waiting for short, interruptable operation
57
+ Sleep = "sleep"
58
+ // Stop marks a stopped process
59
+ Stop = "stop"
60
+ // Wait marks an idle interrupt thread (or paging in pre 2.6.xx Linux)
61
+ Wait = "wait"
62
+ // Zombie marks a defunct process, terminated but not reaped by its parent
63
+ Zombie = "zombie"
64
+
65
+ // Solaris states. See https://github.com/collectd/collectd/blob/1da3305c10c8ff9a63081284cf3d4bb0f6daffd8/src/processes.c#L2115
66
+ Daemon = "daemon"
67
+ Detached = "detached"
68
+ System = "system"
69
+ Orphan = "orphan"
70
+
71
+ UnknownState = ""
55
72
)
56
73
57
74
type OpenFilesStat struct {
@@ -554,23 +571,41 @@ func (p *Process) Environ() ([]string, error) {
554
571
return p .EnvironWithContext (context .Background ())
555
572
}
556
573
574
+ // convertStatusChar as reported by the ps command across different platforms.
557
575
func convertStatusChar (letter string ) string {
576
+ // Sources
577
+ // Darwin: http://www.mywebuniversity.com/Man_Pages/Darwin/man_ps.html
578
+ // FreeBSD: https://www.freebsd.org/cgi/man.cgi?ps
579
+ // Linux https://man7.org/linux/man-pages/man1/ps.1.html
580
+ // OpenBSD: https://man.openbsd.org/ps.1#state
581
+ // Solaris: https://github.com/collectd/collectd/blob/1da3305c10c8ff9a63081284cf3d4bb0f6daffd8/src/processes.c#L2115
558
582
switch letter {
583
+ case "A" :
584
+ return Daemon
585
+ case "D" , "U" :
586
+ return Blocked
587
+ case "E" :
588
+ return Detached
589
+ case "I" :
590
+ return Idle
591
+ case "L" :
592
+ return Lock
593
+ case "O" :
594
+ return Orphan
559
595
case "R" :
560
596
return Running
561
597
case "S" :
562
598
return Sleep
563
- case "T" :
599
+ case "T" , "t" :
600
+ // "t" is used by Linux to signal stopped by the debugger during tracing
564
601
return Stop
565
- case "I" :
566
- return Idle
567
- case "Z" :
568
- return Zombie
569
602
case "W" :
570
603
return Wait
571
- case "L" :
572
- return Lock
604
+ case "Y" :
605
+ return System
606
+ case "Z" :
607
+ return Zombie
573
608
default :
574
- return ""
609
+ return UnknownState
575
610
}
576
611
}
0 commit comments