From patchwork Wed Sep 9 18:12:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Goldish X-Patchwork-Id: 46440 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 n89IFxk6019233 for ; Wed, 9 Sep 2009 18:15:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753944AbZIISPe (ORCPT ); Wed, 9 Sep 2009 14:15:34 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1753932AbZIISPe (ORCPT ); Wed, 9 Sep 2009 14:15:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3542 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753654AbZIISPb (ORCPT ); Wed, 9 Sep 2009 14:15:31 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFYBp019332; Wed, 9 Sep 2009 14:15:34 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n89IFXwB004946; Wed, 9 Sep 2009 14:15:34 -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 n89IFNFS012008; Wed, 9 Sep 2009 14:15:32 -0400 From: Michael Goldish To: autotest@test.kernel.org, kvm@vger.kernel.org Cc: Michael Goldish Subject: [PATCH 07/19] KVM test: kvm_subprocess: get rid of get_pid() (replace it with get_shell_pid()) Date: Wed, 9 Sep 2009 21:12:00 +0300 Message-Id: <1252519932-30733-7-git-send-email-mgoldish@redhat.com> In-Reply-To: <1252519932-30733-6-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> <1252519932-30733-4-git-send-email-mgoldish@redhat.com> <1252519932-30733-5-git-send-email-mgoldish@redhat.com> <1252519932-30733-6-git-send-email-mgoldish@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Don't differentiate between the PID of the subprocess and the PID of the shell running it. Signed-off-by: Michael Goldish --- client/tests/kvm/kvm_subprocess.py | 38 +++++------------------------------ client/tests/kvm/kvm_tests.py | 2 +- 2 files changed, 7 insertions(+), 33 deletions(-) diff --git a/client/tests/kvm/kvm_subprocess.py b/client/tests/kvm/kvm_subprocess.py index ba61a8c..d142ed9 100755 --- a/client/tests/kvm/kvm_subprocess.py +++ b/client/tests/kvm/kvm_subprocess.py @@ -290,10 +290,12 @@ class kvm_spawn: return self.id - def get_shell_pid(self): + def get_pid(self): """ - Return the PID of the subshell process, or None if not available. - The subshell is the shell that runs the command. + Return the PID of the process. + + Note: this may be the PID of the shell process running the user given + command. """ try: file = open(self.shell_pid_filename, "r") @@ -304,34 +306,6 @@ class kvm_spawn: return None - def get_pid(self, index=0): - """ - Try to get and return the PID of a child process of the subshell. - This is usually the PID of the process executed in the subshell. - There are 3 exceptions: - - If the subshell couldn't start the process for some reason, no - PID can be returned. - - If the subshell is running several processes in parallel, - multiple PIDs can be returned. Use the index parameter in this - case. - - Before starting the process, after the process has terminated, - or while running shell code that doesn't start any processes -- - no PID can be returned. - - @param index: The index of the child process whose PID is requested. - Normally this should remain 0. - @return: The PID of the child process, or None if none could be found. - """ - parent_pid = self.get_shell_pid() - if not parent_pid: - return None - pids = commands.getoutput("ps --ppid %d -o pid=" % parent_pid).split() - try: - return int(pids[index]) - except: - return None - - def get_status(self): """ Wait for the process to exit and return its exit status, or None @@ -375,7 +349,7 @@ class kvm_spawn: """ # Kill it if it's alive if self.is_alive(): - kvm_utils.kill_process_tree(self.get_shell_pid(), sig) + kvm_utils.kill_process_tree(self.get_pid(), sig) # Wait for the server to exit _wait(self.lock_server_running_filename) # Call all cleanup routines diff --git a/client/tests/kvm/kvm_tests.py b/client/tests/kvm/kvm_tests.py index deab59e..c2bfb8a 100644 --- a/client/tests/kvm/kvm_tests.py +++ b/client/tests/kvm/kvm_tests.py @@ -688,7 +688,7 @@ def run_timedrift(test, params, env): output_prefix="(host load %d) " % i, timeout=0.5)) # Set the CPU affinity of the load process - pid = host_load_sessions[-1].get_shell_pid() + pid = host_load_sessions[-1].get_pid() set_cpu_affinity(pid, cpu_mask) # Sleep for a while (during load)