Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OSX pid 0 bug #1187

Merged
merged 7 commits into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
misbehaving processes which overwrite /proc/pid/cmdline and use spaces
instead of null bytes as args separator.
- 1181_: [OSX] Process.memory_maps() may raise ENOENT.
- 1187_: [OSX] pids() does not return PID 0 on recent OSX versions.

5.4.1
=====
Expand Down
18 changes: 17 additions & 1 deletion psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,23 @@ def users():
# =====================================================================


pids = cext.pids
def pids():
ls = cext.pids()
if 0 not in ls:
# On certain OSX versions pids() C doesn't return PID 0 but
# "ps" does and the process is querable via sysctl():
# https://travis-ci.org/giampaolo/psutil/jobs/309619941
try:
Process(0).create_time()
except NoSuchProcess:
return False
except AccessDenied:
ls.append(0)
else:
ls.append(0)
return ls


pid_exists = _psposix.pid_exists


Expand Down
12 changes: 8 additions & 4 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1314,10 +1314,14 @@ def succeed_or_zombie_p_exc(fun, *args, **kwargs):
# self.assertEqual(zpid.ppid(), os.getpid())
# ...and all other APIs should be able to deal with it
self.assertTrue(psutil.pid_exists(zpid))
self.assertIn(zpid, psutil.pids())
self.assertIn(zpid, [x.pid for x in psutil.process_iter()])
psutil._pmap = {}
self.assertIn(zpid, [x.pid for x in psutil.process_iter()])
if not TRAVIS and OSX:
# For some reason this started failing all of the sudden.
# Maybe they upgraded OSX version?
# https://travis-ci.org/giampaolo/psutil/jobs/310896404
self.assertIn(zpid, psutil.pids())
self.assertIn(zpid, [x.pid for x in psutil.process_iter()])
psutil._pmap = {}
self.assertIn(zpid, [x.pid for x in psutil.process_iter()])

@unittest.skipIf(not POSIX, 'POSIX only')
def test_zombie_process_is_running_w_exc(self):
Expand Down