Add utils.pid_is_alive() which discriminates between zombie tasks and fully-alive tasks.

Signed-off-by: Duane Sand <duanes@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3283 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/common_lib/utils.py b/client/common_lib/utils.py
index 769e9fe..93617ed 100644
--- a/client/common_lib/utils.py
+++ b/client/common_lib/utils.py
@@ -511,6 +511,19 @@
             pass
 
 
+def pid_is_alive(pid):
+    """
+    True if process pid exists and is not yet stuck in Zombie state.
+    Zombies are impossible to move between cgroups, etc.
+    pid can be integer, or text of integer.
+    """
+    try:
+        stat = utils.read_one_line('/proc/%s/stat' % pid)  # pid exists
+        return stat.split()[2] != 'Z'  # and is not in Zombie state
+    except Exception:
+        return False  # process no longer exists at all
+
+
 def system(command, timeout=None, ignore_status=False):
     """This function returns the exit status of command."""
     return run(command, timeout=timeout, ignore_status=ignore_status,