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

[Linux] memory_full_info() incorrectly raise ZombieProcess #2284

Merged
merged 2 commits into from Aug 1, 2023

Conversation

giampaolo
Copy link
Owner

Summary

  • OS: Linux
  • Type: core

Description

...this happens, for example, with PID 2 (kthreadd):

>>> import psutil
>>> psutil.Process(2).memory_info()
pmem(rss=0, vms=0, shared=0, text=0, lib=0, data=0, dirty=0)
>>> psutil.Process(2).memory_full_info()
Traceback (most recent call last):
  File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1901, in _parse_smaps_rollup
    for line in f:
ProcessLookupError: [Errno 3] No such process

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/giampaolo/svn/psutil/psutil/__init__.py", line 1091, in memory_full_info
    return self._proc.memory_full_info()
  File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1948, in memory_full_info
    uss, pss, swap = self._parse_smaps_rollup()
  File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1653, in wrapper
    return fun(self, *args, **kwargs)
  File "/home/giampaolo/svn/psutil/psutil/_pslinux.py", line 1913, in _parse_smaps_rollup
    raise ZombieProcess(self.pid, self._name, self._ppid)
psutil.ZombieProcess: PID still exists but it's a zombie (pid=2)

The error originates from /proc/pid/smaps_rollup, which acts weirdly: it raises ESRCH / ENOENT for many PIDs, even if they're alive (also as root). In that case we'll have to use /proc/pid/smaps as fallback, which is slower but has a +50% success rate compared to /proc/pid/smaps_rollup.

@github-actions github-actions bot added the linux label Aug 1, 2023
@giampaolo giampaolo merged commit 1b7a3e1 into master Aug 1, 2023
20 of 26 checks passed
@giampaolo giampaolo deleted the memory_full_info_zombie branch August 1, 2023 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant