From patchwork Wed Sep 9 18:11:57 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 46426 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n89IFb85019128 for ; Wed, 9 Sep 2009 18:15:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753942AbZIISPa (ORCPT ); Wed, 9 Sep 2009 14:15:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753919AbZIISPa (ORCPT ); Wed, 9 Sep 2009 14:15:30 -0400 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 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFVx5019325; Wed, 9 Sep 2009 14:15:31 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFT3w015354; Wed, 9 Sep 2009 14:15:31 -0400 Received: from localhost.localdomain (dhcp-1-188.tlv.redhat.com [10.35.1.188]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFNFP012008; Wed, 9 Sep 2009 14:15:28 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: 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> In-Reply-To: <1252519932-30733-3-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> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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.