-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
pids: Search for process name matches in the cmdline #59318
Conversation
The test
The test
|
fixed, thanks ansibae ❤️ ready_for_review |
@Akasurde you've reviewed changes to this module before, mind taking a look at this one? |
@wmedlar Sure, Thanks. |
return [p.info['pid'] for p in psutil.process_iter(attrs=['pid', 'name']) if p.info and p.info.get('name', None) and p.info['name'].lower() == name.lower()] | ||
pids = [] | ||
|
||
for proc in psutil.process_iter(attrs=['name', 'cmdline']): |
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.
Shouldn't this be including 'pid' as per original code ?
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.
Only if you access the pid through the p.info
dict attribute; the Process
object itself will always have a pid
attribute set.
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.
@Akasurde thoughts?
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.
@Akasurde ping
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.
@wmedlar Sorry for delay, I will take a look.
Can anyone else take a look at this? |
* Also search for process name matches in the cmdline * Return integer pids * Use correct variable name * Fix linter concerns
SUMMARY
This more appropriately matches the behavior of
pidof
and allows thepids
module to work with processes invoked withexec -a SOMENAME
.ISSUE TYPE
COMPONENT NAME
pids
ADDITIONAL INFORMATION
pidof
behavior:$ (exec -a PIDOF-TEST sleep 100) & [1] 373 $ pidof PIDOF-TEST 373
pids
module behavior prior to this change:pids
module behavior after this change:This code is inspired by psutil's Python clone of pidof.