Skip to content

Commit

Permalink
[Plugin] add get_process_pids() to return PIDs by process name
Browse files Browse the repository at this point in the history
Signed-off-by: Irit Goihman igoihman@redhat.com
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
  • Loading branch information
igoihman authored and bmr-cymru committed Apr 15, 2019
1 parent 9b1f947 commit 1b4f8df
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions sos/plugins/__init__.py
Expand Up @@ -1389,6 +1389,22 @@ def check_process_by_name(self, process):
return False
return status

def get_process_pids(self, process):
"""Returns PIDs of all processes with process name.
If the process doesn't exist, returns an empty list"""
pids = []
cmd_line_glob = "/proc/[0-9]*/cmdline"
cmd_line_paths = glob.glob(cmd_line_glob)
for path in cmd_line_paths:
try:
with open(path, 'r') as f:
cmd_line = f.read().strip()
if process in cmd_line:
pids.append(path.split("/")[2])
except IOError as e:
continue
return pids


class RedHatPlugin(object):
"""Tagging class for Red Hat's Linux distributions"""
Expand Down

0 comments on commit 1b4f8df

Please sign in to comment.