summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2016-12-20 20:22:32 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2016-12-20 20:22:32 +0100
commit039ba9079120fa40c22918fe8d02465f22a0dd4a (patch)
tree92871480d45f69ee0803eb39771f1a93afd4aaaa
parentc9a417a6ba06aa9d504c24ec6104bdea58e9ab66 (diff)
downloadpsutil-039ba9079120fa40c22918fe8d02465f22a0dd4a.tar.gz
fix #944: [OpenBSD] psutil.pids() was omitting PID 0
-rw-r--r--HISTORY.rst1
-rw-r--r--psutil/_psbsd.py22
2 files changed, 22 insertions, 1 deletions
diff --git a/HISTORY.rst b/HISTORY.rst
index fdd59e76..f21c4c20 100644
--- a/HISTORY.rst
+++ b/HISTORY.rst
@@ -18,6 +18,7 @@
- 940_: [Linux] cpu_percent() and cpu_times_percent() was calculated
incorrectly as "iowait", "guest" and "guest_nice" times were not properly
taken into account.
+- 944_: [OpenBSD] psutil.pids() was omitting PID 0.
5.0.0
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index a3301504..acf6c7c3 100644
--- a/psutil/_psbsd.py
+++ b/psutil/_psbsd.py
@@ -17,6 +17,7 @@ from . import _psutil_bsd as cext
from . import _psutil_posix as cext_posix
from ._common import conn_tmap
from ._common import FREEBSD
+from ._common import memoize
from ._common import memoize_when_activated
from ._common import NETBSD
from ._common import OPENBSD
@@ -420,7 +421,26 @@ def users():
# =====================================================================
-pids = cext.pids
+@memoize
+def _pid_0_exists():
+ try:
+ Process(0).name()
+ except NoSuchProcess:
+ return False
+ except AccessDenied:
+ return True
+ else:
+ return True
+
+
+def pids():
+ ret = cext.pids()
+ if OPENBSD and (0 not in ret) and _pid_0_exists():
+ # On OpenBSD the kernel does not return PID 0 (neither does
+ # ps) but it's actually querable (Process(0) will succeed).
+ ret.insert(0, 0)
+ return ret
+
if OPENBSD or NETBSD:
def pid_exists(pid):