aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoririt.go <igoihman@redhat.com>2018-07-24 11:01:55 +0300
committerBryn M. Reeves <bmr@redhat.com>2019-04-15 17:48:12 +0100
commit1b4f8dfb8ac85708441faa3b2c2b9c2624dfa155 (patch)
treef49d528573c24ceee6ea62ae423af9e20a7a5dbb
parent9b1f9472e7b0b8a993f635c8d4c757b59c46ed0f (diff)
downloadsos-1b4f8dfb8ac85708441faa3b2c2b9c2624dfa155.tar.gz
[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 <bmr@redhat.com>
-rw-r--r--sos/plugins/__init__.py16
1 files changed, 16 insertions, 0 deletions
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"""