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
[macOS] cmdline() raises NoSuchProcess on EINVAL #2189
Comments
That's a race condition: between the for proc in psutil.process_iter(attrs=["name", "cmdline"]):
print(proc.info["name"])
print(proc.info["cmdline"]) ...or you catch the exception later: for proc in psutil.process_iter():
try:
print(proc.name())
print(proc.cmdline())
except (psutil.NoSuchProcess, psutil.AccessDenied):
continue |
Thank you! I used the first method |
@giampaolo I'm confused why the process no longer exists when the terminal session is still open. The race shouldn't really exist because the process never closed And it seems to be a new problem that didn't happen in 5.6.7 |
Perhaps this is expected behavior, however I find it surprising on two counts. First, I have independently confirmed just now that no such exception is raised with version 5.6.7, but after upgrading to 5.9.4, the exception is thrown. Secondly, it is the same process that consistently throws the error on my machine (M1 Macbook Pro, Ventura 13.0.1): the 'login -pf username' process running under root. Moreover, the process is still running under the same pid. I suggest that this warrants re-opening the issue. |
Mmm... even if the original python code had race condition, this may indeed be an actual bug. Error originates from here: psutil/psutil/arch/osx/process_info.c Line 135 in c6b7145
Is the process a zombie? Can you guys please catch the NoSuchProcess exception and then print the process status() ?
|
The status is running: It seems to be caused by Mac's permissions to root processes. When the code is run on |
Hmm. That seems to be right. No exception raised if I run the python process with sudo. |
Note to self: the problem is that In order to fix this I'll have to refactor the C code a bit though, so this may take a while. |
Recreated the problem I was facing:
When I looked online about similar errors, some suggested it was caused by a zombie process. So I tried to kill the process and the terminal session closed.
I'm not sure if this is a bug or a feature, but this only happened when I updated psutil from 5.6.7 to 5.9.4
The text was updated successfully, but these errors were encountered: