Browse Source

New attempt at killing processes

msmith-techempower 8 years ago
parent
commit
4ca78cfd11
2 changed files with 25 additions and 10 deletions
  1. 25 4
      toolset/benchmark/benchmarker.py
  2. 0 6
      toolset/setup/linux/TFBReaper.c

+ 25 - 4
toolset/benchmark/benchmarker.py

@@ -692,15 +692,36 @@ class Benchmarker:
   ############################################################
   ############################################################
   def __stop_test(self, out, process):
   def __stop_test(self, out, process):
     if process is not None:
     if process is not None:
-      # Kill the children
-      subprocess.call(['pkill', '-P', process.pid], stderr=out, stdout=out)
-      # Kill the parent 
+      pids = self.__find_child_processes(process.pid)
+      if pids is not None:
+        kill = ['kill','-9'] + pids
+        subprocess.call(kill, stderr=out, stdout=out)
       process.terminate()
       process.terminate()
-
   ############################################################
   ############################################################
   # End __stop_test
   # End __stop_test
   ############################################################
   ############################################################
 
 
+  ############################################################
+  # __find_child_processes
+  # Recursively finds all child processes for the given PID.
+  ############################################################
+  def __find_child_processes(self, pid):
+  toRet = []
+  try:
+    pids = subprocess.check_output(['pgrep','-P',str(pid)]).split()
+    toRet.extend(pids)
+    for aPid in pids:
+      toRet.extend(self.__find_child_processes(aPid))
+  except:
+    # pgrep will return a non-zero status code if there are no
+    # processes who have a PPID of PID.
+    pass
+
+  return toRet
+  ############################################################
+  # End __find_child_processes
+  ############################################################
+
   def is_port_bound(self, port):
   def is_port_bound(self, port):
     return self.__is_port_bound(port)
     return self.__is_port_bound(port)
 
 

+ 0 - 6
toolset/setup/linux/TFBReaper.c

@@ -40,12 +40,6 @@ int main(int argc, char *argv[])
   // See: http://man7.org/linux/man-pages/man2/prctl.2.html
   // See: http://man7.org/linux/man-pages/man2/prctl.2.html
   prctl(PR_SET_CHILD_SUBREAPER,1);
   prctl(PR_SET_CHILD_SUBREAPER,1);
 
 
-  // Sets the process group id to that of the process id of
-  // this process. All child processes should inherit this
-  // group id unless setpgrp is called directly (which some
-  // will do).
-  setpgrp();
-
   // This invokes whatever was passed as arguments to TFBReaper
   // This invokes whatever was passed as arguments to TFBReaper
   // on the system. This program is merely a pass-through to
   // on the system. This program is merely a pass-through to
   // a shell with the subreaper stuff enabled.
   // a shell with the subreaper stuff enabled.