[autotest] add a method to get pid and command line of oldest process with name matches |name|
BUG=chromium:289702
TEST=None
Change-Id: I8942e704df64b0283b884d3aea19437f40921116
Reviewed-on: https://chromium-review.googlesource.com/174102
Reviewed-by: Achuith Bhandarkar <achuith@chromium.org>
Commit-Queue: Dan Shi <dshi@chromium.org>
Tested-by: Dan Shi <dshi@chromium.org>
diff --git a/client/bin/site_utils.py b/client/bin/site_utils.py
index e79986c..c14416c 100644
--- a/client/bin/site_utils.py
+++ b/client/bin/site_utils.py
@@ -76,6 +76,21 @@
return int(str_pid)
+def get_oldest_by_name(name):
+ """Return pid and command line of oldest process whose name matches |name|.
+
+ @param name: egrep expression to match desired process name.
+ @return: A tuple of (pid, command_line) of the oldest process whose name
+ matches |name|.
+
+ """
+ pid = get_oldest_pid_by_name(name)
+ if pid:
+ command_line = utils.system_output('ps -p %i -o command=' % pid,
+ ignore_status=True).rstrip()
+ return (pid, command_line)
+
+
def get_process_list(name, command_line=None):
"""
Return the list of pid for matching process |name command_line|.