-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Use the proc filesystem to gather process information #1886
Conversation
cool |
with open('/proc/{0}/cmdline'.format(pid), 'r') as fh: | ||
return fh.read().replace('\0', ' ').rstrip() | ||
except IOError: | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is swallowing this exception about? When and for who will it occur? Maybe you can add a comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added commit 1836dd2 with a comment
Isn't it better to actually throw an exception instead of using a fallback-method when there's a file permissions error? I imagine an admin mis-configuring so that two different users run the same command. It's better to report an error early rather than always running in a |
The former implementation as well as the implementation for windows systems both do not raise any errors when a pid can not be resolved. Reasons I can think of may be missing permissions or simply that the process in the meantime has exited. Instead the fallback at the end of the function is used. So there is always a string retruned giving some description on the process. This PR simply preserves this behavior of the getpcmp function. The function tries to resolve the command of the given pid and returns the most meaningful description possible. In case the desired behavior of Maybe you should also discuss this with @erikbern , the original author of the |
@nmandery, You seem to have thought about this more thoroughly than I have. And admittedly know more about OS/procs/etc than me. :) Furthermore you just documented your thought-process in case further committers want to read up on this. Thanks. I feel confident enough to merge this. :) |
@nmandery, I took the liberty to myself summarize why we did this in the squash-commit I just merged this PR with. I hope it looks good. |
@Tarrasch Looks fine to me. Thank you for merging and the reviews. |
Description
This pull request uses the proc filesystem to gather process information instead of calling the
ps
command.Motivation and Context
See the discussion at PR #1876