From: Michael Goldish Subject: [PATCH 04/19] KVM test: kvm_utils.py: add kill_process_tree() Date: Wed, 9 Sep 2009 21:11:57 +0300 Message-ID: <1252519932-30733-4-git-send-email-mgoldish@redhat.com> References: <1252519932-30733-1-git-send-email-mgoldish@redhat.com> <1252519932-30733-2-git-send-email-mgoldish@redhat.com> <1252519932-30733-3-git-send-email-mgoldish@redhat.com> Cc: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:33106 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753932AbZIISP2 (ORCPT ); Wed, 9 Sep 2009 14:15:28 -0400 In-Reply-To: <1252519932-30733-3-git-send-email-mgoldish@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_utils.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/client/tests/kvm/kvm_utils.py b/client/tests/kvm/kvm_utils.py index f046810..f686a53 100644 --- a/client/tests/kvm/kvm_utils.py +++ b/client/tests/kvm/kvm_utils.py @@ -265,6 +265,23 @@ def safe_kill(pid, signal): return False +def kill_process_tree(pid, sig=signal.SIGKILL): + """Signal a process and all of its children. + + If the process does not exist -- return. + + @param pid: The pid of the process to signal. + @param sig: The signal to send to the processes. + """ + if not safe_kill(pid, signal.SIGSTOP): + return + children = commands.getoutput("ps --ppid=%d -o pid=" % pid).split() + for child in children: + kill_process_tree(int(child), sig) + safe_kill(pid, sig) + safe_kill(pid, signal.SIGCONT) + + def get_latest_kvm_release_tag(release_dir): """ Fetches the latest release tag for KVM. -- 1.5.4.1