@@ -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
@@ -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)
Don't differentiate between the PID of the subprocess and the PID of the shell running it. Signed-off-by: Michael Goldish <mgoldish@redhat.com> --- client/tests/kvm/kvm_subprocess.py | 38 +++++------------------------------ client/tests/kvm/kvm_tests.py | 2 +- 2 files changed, 7 insertions(+), 33 deletions(-)