From 3e5ce99e82dcab619d1b0412b5117545ae4f7017 Mon Sep 17 00:00:00 2001 From: James Prestwood Date: Fri, 24 Jun 2022 16:07:35 -0700 Subject: [PATCH] test-runner: make is_process_running more accurate This function was checking if the process object exists, which can persist long after a process is killed, or dies unexpectedly. Check that the actual PID exists by sending signal 0. --- tools/utils.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/utils.py b/tools/utils.py index 857aa1eb..7272c1f9 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -342,10 +342,24 @@ class Namespace: def stop_process(self, p, force=False): p.kill(force) + def _is_running(self, pid): + try: + os.kill(pid, 0) + except OSError: + return False + + return True + def is_process_running(self, process): for p in Process.get_all(): - if p.namespace == self.name and p.args[0] == process: - return True + # Namespace processes are actually started by 'ip' where + # the actual process name is at index 4 of the arguments. + idx = 0 if not p.namespace else 4 + + if p.namespace == self.name and p.args[idx] == process: + # The process object exists, but make sure its + # actually running. + return self._is_running(p.pid) return False def _cleanup_dbus(self):