Skip to content

Commit

Permalink
fix #925: [OSX/BSD/SUNOS] ZombieProcess may be erroneously raised for…
Browse files Browse the repository at this point in the history
… PID 0
  • Loading branch information
giampaolo committed Oct 17, 2016
1 parent 5887f56 commit bf15b4c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Expand Up @@ -41,6 +41,7 @@ Bug tracker at https://github.com/giampaolo/psutil/issues
original one, hopefully helping the gc to free resources.
- #923: [OSX] free memory is wrong (does not match vm_stat command).
- #924: [OSX] Process.exe() for PID 0 erroneously raise ZombieProcess.
- #925: [OSX/BSD/SUNOS] ZombieProcess may be erroneously raised for PID 0.


4.3.1 - 2016-09-01
Expand Down
5 changes: 5 additions & 0 deletions psutil/_psbsd.py
Expand Up @@ -411,6 +411,11 @@ def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except OSError as err:
if self.pid == 0:
if 0 in pids():
raise AccessDenied(self.pid, self._name)
else:
raise
if err.errno == errno.ESRCH:
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
Expand Down
5 changes: 5 additions & 0 deletions psutil/_psosx.py
Expand Up @@ -243,6 +243,11 @@ def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except OSError as err:
if self.pid == 0:
if 0 in pids():
raise AccessDenied(self.pid, self._name)
else:
raise
if err.errno == errno.ESRCH:
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
Expand Down
5 changes: 5 additions & 0 deletions psutil/_pssunos.py
Expand Up @@ -323,6 +323,11 @@ def wrapper(self, *args, **kwargs):
try:
return fun(self, *args, **kwargs)
except EnvironmentError as err:
if self.pid == 0:
if 0 in pids():
raise AccessDenied(self.pid, self._name)
else:
raise
# ENOENT (no such file or directory) gets raised on open().
# ESRCH (no such process) can get raised on read() if
# process is gone in meantime.
Expand Down
6 changes: 6 additions & 0 deletions psutil/tests/test_process.py
Expand Up @@ -1427,6 +1427,12 @@ def test_pid_0(self):
elif name == "name":
assert name, name

if hasattr(p, 'rlimit'):
try:
p.rlimit(psutil.RLIMIT_FSIZE)
except psutil.AccessDenied:
pass

p.as_dict()

if not OPENBSD:
Expand Down

0 comments on commit bf15b4c

Please sign in to comment.