Add process_is_alive() to client/bin/base_utils. Use a smart pgrep command which finds the python processes not found by plain pgrep. Signed-off-by: Duane Sand <[email protected]> git-svn-id: http://test.kernel.org/svn/autotest/trunk@3617 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/client/bin/base_utils.py b/client/bin/base_utils.py index d6099dc..c7a1a06 100755 --- a/client/bin/base_utils.py +++ b/client/bin/base_utils.py
@@ -653,3 +653,13 @@ utils.system("sync") # We ignore failures here as this will fail on 2.6.11 kernels. utils.system("echo 3 > /proc/sys/vm/drop_caches", ignore_status=True) + + +def process_is_alive(name): + """ + 'pgrep name' misses all python processes and also long process names. + 'pgrep -f name' gets all shell commands with name in args. + So look only for command whose first nonblank word ends with name. + """ + return utils.system("pgrep -f '^[^ ]*%s\W'" % name, + ignore_status=True) == 0