the-gigi · GitHub

This is on a Mac OSX El Capitan Here is a quick session to demonstrate. Process 70 on my machine right now is indeed a zombie process.

Python 2.7.10 (default, Jun 10 2015, 19:43:32)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>> psutil.__version__
'4.0.0'
>>> p = psutil.Process(pid=70)
>>> p.status()
'running'
>>> p.name()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/gigi/.virtualenvs/work/lib/python2.7/site-packages/psutil/__init__.py", line 564, in name
    cmdline = self.cmdline()
  File "/Users/gigi/.virtualenvs/work/lib/python2.7/site-packages/psutil/__init__.py", line 617, in cmdline
    return self._proc.cmdline()
  File "/Users/gigi/.virtualenvs/work/lib/python2.7/site-packages/psutil/_psosx.py", line 207, in wrapper
    raise ZombieProcess(self.pid, self._name, self._ppid)
psutil.ZombieProcess: psutil.ZombieProcess process still exists but it's a zombie (pid=70)

I followed the code to the status() method in _psxosx.py to see why it returns 'running'

    @wrap_exceptions
    def status(self):
        code = cext.proc_status(self.pid)
        # XXX is '?' legit? (we're not supposed to return it anyway)
        return PROC_STATUSES.get(code, '?')

The cext.proc_status(self.pid) returns 2, which is the code for 'running'.

Read the original on github.com ↗