-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add an utility function like psutil.process_iter() #186
Comments
I have not measured performance, but gopsutil's Off course, PR is always welcome! |
This isn't a performance issue, it's a correctness issue. As it stands, it is impossible to get information about a consistent list of currently running processes. The only mechanism for getting running processes is |
To add to my prior comment... using pids as the primary identifier is deeply troubling. Consider:
This appears to be obviously correct, but the library uses pids under the hood. The pids can be reused between the time that |
@alficles
|
|
What does this PID cache has? I don't see how it would solve the problem that @alficles demostrated with his snippet. The cache must contain the process PID, which is used to manage and kill the process. The only way to avoid the problem would be to, before handling the process, compare other info attached to the process (ie. command line arguments, user, nice value, etc) with the one in the cache. |
I don't know the inner code of |
@mirath Even verification isn't enough to be sure. In the intervening time between verifying the information and killing the process, the pid may have been killed and reused. |
If i am not mistaken, actually the only way to make iteration with the processes is by using
process.Pids()
. In the psutils documentation it is not recommended for iterations because of possible PIDs number reuses.For now, using
process.Pids()
is somewhat Ok, but implementing a PID cache like inpsutil.process_iter()
would be a good improvement :)The text was updated successfully, but these errors were encountered: