process.Process.uids is an array of undocumented values.
That one of them is the user that the process is running as is obvious, but what
the other two are supposed to be is AFAICT undocumented.
On Darwin, the second and third UID (out of three) seem to always be 0.
This change removes the two always-zero UIDs from the process.Process struct on
Darwin, and leaves just the one that actually identifies the user the process
is running as.
This function used to be a private part of process.go.
Since I needed that functionality however I think it's better to make it public
than for me to copy it into my own code.
As a side effect of this change, I also fixed a bug in the function where Stolen
was not part of the sum. Having the function close to the CPUTimesStat
declaration will make problems like this less likely to re-occur in the future.
FreeBSD apparently changed the magic sysctl mib values for devstats.
--- FAIL: TestDisk_io_counters (0.00s)
disk_test.go:39: error no such file or directory
disk_test.go:42: ret is empty, map[]
This code uses an undocumented, but exported, go stdlib method to fetch
the sysctl by string instead of mib.
system (no pgrep command) and one is a normal error state of pgrep
meaning no processes found for the criteria given (in this case the parent
pid does not exist or the process simply has no children). The later case
is quite usefull to know about so I added a static error for this case.
host_darwin does the same filtering. Not doing this gives us some rather strange
entries that likely aren't what we want.
Before:
{"user":"reboot","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378260}
{"user":"LOGIN","terminal":"ttyS0","host":"","started":1454378270}
{"user":"LOGIN","terminal":"tty1","host":"","started":1454378270}
{"user":"runlevel","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378276}
{"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}
After:
{"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}