summaryrefslogtreecommitdiff
path: root/psutil/_psbsd.py
diff options
context:
space:
mode:
authorGiampaolo Rodola <g.rodola@gmail.com>2017-01-23 23:06:30 +0100
committerGiampaolo Rodola <g.rodola@gmail.com>2017-01-23 23:06:30 +0100
commit5f186957a4ae6505810488c7b3118453c459fdec (patch)
tree43ee8a0811724b2d6bbd267808ee49b3becf08f6 /psutil/_psbsd.py
parent29496900f772c8c594fa9c5142a88a5291c05f55 (diff)
parentf8c07ae1082ee07fd08c25fa163fc8edb31e5b7f (diff)
downloadpsutil-5f186957a4ae6505810488c7b3118453c459fdec.tar.gz
merge from master
Diffstat (limited to 'psutil/_psbsd.py')
-rw-r--r--psutil/_psbsd.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py
index 0a14bf80..022f5758 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
@@ -421,7 +422,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):