From 1b4f8dfb8ac85708441faa3b2c2b9c2624dfa155 Mon Sep 17 00:00:00 2001 From: "irit.go" Date: Tue, 24 Jul 2018 11:01:55 +0300 Subject: [Plugin] add get_process_pids() to return PIDs by process name Signed-off-by: Irit Goihman igoihman@redhat.com Signed-off-by: Bryn M. Reeves --- sos/plugins/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index 4c8822b7..cdeda77a 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -1389,6 +1389,22 @@ class Plugin(object): 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""" -- cgit