diff --git a/osbenchmark/utils/process.py b/osbenchmark/utils/process.py index a5b681bd4..95446e7b2 100644 --- a/osbenchmark/utils/process.py +++ b/osbenchmark/utils/process.py @@ -133,11 +133,12 @@ def run_subprocess_with_logging(command_line, header=None, level=logging.INFO, s def is_benchmark_process(p): cmdline = p.cmdline() + # On Linux, /proc/PID/status truncates the command name to 15 characters. return p.name() == "opensearch-benchmark" or \ - (p.name().lower().startswith("python") and - (len(cmdline) > 1 and - (cmdline[1] == "opensearch-benchmark" or - cmdline[1].endswith(os.path.sep + "opensearch-benchmark")))) + p.name() == "opensearch-benc" or \ + (len(cmdline) > 1 and + os.path.basename(cmdline[0].lower()).startswith("python") and + os.path.basename(cmdline[1]) == "opensearch-benchmark") def find_all_other_benchmark_processes(): diff --git a/tests/utils/process_test.py b/tests/utils/process_test.py index 4b5631915..07f6c84d1 100644 --- a/tests/utils/process_test.py +++ b/tests/utils/process_test.py @@ -123,6 +123,8 @@ def test_kills_only_benchmark_processes(self, process_iter): random_python = ProcessTests.Process(103, "python3", ["/some/django/app"]) other_process = ProcessTests.Process(104, "init", ["/usr/sbin/init"]) benchmark_process_p = ProcessTests.Process(105, "python3", ["/usr/bin/python3", "~/.local/bin/opensearch-benchmark"]) + # On Linux, the process name is truncated to 15 characters. + benchmark_process_l = ProcessTests.Process(106, "opensearch-benc", ["/usr/bin/python3", "~/.local/bin/osbenchmark"]) benchmark_process_e = ProcessTests.Process(107, "opensearch-benchmark", ["/usr/bin/python3", "~/.local/bin/opensearch-benchmark"]) benchmark_process_mac = ProcessTests.Process(108, "Python", ["/Python.app/Contents/MacOS/Python", "~/.local/bin/opensearch-benchmark"]) @@ -139,6 +141,7 @@ def test_kills_only_benchmark_processes(self, process_iter): random_python, other_process, benchmark_process_p, + benchmark_process_l, benchmark_process_e, benchmark_process_mac, own_benchmark_process, @@ -153,6 +156,7 @@ def test_kills_only_benchmark_processes(self, process_iter): self.assertFalse(random_python.killed) self.assertFalse(other_process.killed) self.assertTrue(benchmark_process_p.killed) + self.assertTrue(benchmark_process_l.killed) self.assertTrue(benchmark_process_e.killed) self.assertTrue(benchmark_process_mac.killed) self.assertFalse(own_benchmark_process.killed)