Skip to content

Commit

Permalink
fix #944: [OpenBSD] psutil.pids() was omitting PID 0
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 20, 2016
1 parent c9a417a commit 039ba90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 21 additions & 1 deletion psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 039ba90

Please sign in to comment.