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

is_running() always return true on process created by psutil.Popen #1008

Closed
JasonXJ opened this issue Apr 7, 2017 · 3 comments
Closed

is_running() always return true on process created by psutil.Popen #1008

JasonXJ opened this issue Apr 7, 2017 · 3 comments

Comments

@JasonXJ
Copy link

JasonXJ commented Apr 7, 2017

is_running() always returns true on a process created by psutil.Popen(), even after the process is already dead.

This is the code I ran on ipython. At command [79], pgrep already confirmed that the process was not there, but at [80], is_running() returned true.

In [77]: p = psutil.Popen('sleep  5', shell=True)

In [78]: !pgrep -af 'sleep 5'
22725 sleep 5

In [79]: !pgrep -af 'sleep 5'

In [80]: p.is_running()
Out[80]: True

This is some version information:

In [92]: psutil.__version__
Out[92]: '5.2.1'

In [93]: !lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:        16.04
Codename:       xenial

In [94]: import sys; sys.version
Out[94]: '3.5.2 (default, Nov 17 2016, 17:05:23) \n[GCC 5.4.0 20160609]'
@giampaolo
Copy link
Owner

That's correct as the real process is not "sleep", it's the shell ("sh"), which is still alive as a zombie, and zombies are technically still running and querable:

>>> p = psutil.Popen('sleep  5', shell=True)
>>> # wait 5 secs
>>> p.name()
'sh'
>>> p.status()
'zombie'
>>> p.pid
20504
>>> 20504 in psutil.pids()
True
~/svn/cpython/Lib/asyncio$ ps aux | grep 20504
giampao+ 20504  0.0  0.0      0     0 pts/17   Z+   12:54   0:00 [sh] <defunct>

@nate-jackson
Copy link

nate-jackson commented Jul 8, 2019

Is there a way to tell if it's a zombie when using process_iter and oneshot()?

for proc in psutil.process_iter():
    with proc.oneshot():
        is_zombie = ?

@nate-jackson
Copy link

found it
proc.status() == 'zombie'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants