Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[tesh] kill process -> kill whole process group
authorMillian Poquet <millian.poquet@inria.fr>
Mon, 19 Feb 2018 10:52:25 +0000 (11:52 +0100)
committerMillian Poquet <millian.poquet@inria.fr>
Mon, 19 Feb 2018 10:59:54 +0000 (11:59 +0100)
If the command launched by tesh executes some subprocesses
(which are not cleaned by the root process on SIGKILL)
the previous code let such subprocesses in a running state.

Now the root process is launched into a new session (man setsid)
and the whole session is killed by tesh. All subprocess should be killed
as long as the session is not changed in the process tree.

Traversing the process tree could also be done, but it may require
additional dependencies (i.e., psutil).

tools/tesh/tesh.py

index 5db0dcb..a8d52eb 100755 (executable)
@@ -290,7 +290,7 @@ class Cmd(object):
         #print (args)
 
         try:
-            proc = subprocess.Popen(args, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)
+            proc = subprocess.Popen(args, bufsize=1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, preexec_fn=os.setsid)
         except FileNotFoundError:
             print("["+FileReader().filename+":"+str(self.linenumber)+"] Cannot start '"+args[0]+"': File not found")
             tesh_exit(3)
@@ -304,7 +304,7 @@ class Cmd(object):
             (stdout_data, stderr_data) = proc.communicate("\n".join(self.input_pipe), self.timeout)
         except subprocess.TimeoutExpired:
             print("Test suite `"+FileReader().filename+"': NOK (<"+cmdName+"> timeout after "+str(self.timeout)+" sec)")
-            proc.kill()
+            os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
             tesh_exit(3)
 
         if self.output_display: