[Lldb-commits] [PATCH] D83815: [lldb/Test] Use a process group for subprocesses

Jonas Devlieghere via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Jul 14 14:55:14 PDT 2020


JDevlieghere updated this revision to Diff 277989.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83815/new/

https://reviews.llvm.org/D83815

Files:
  lldb/packages/Python/lldbsuite/test/lldbtest.py


Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -428,6 +428,7 @@
             stdout=PIPE,
             stderr=PIPE,
             shell=True,
+            preexec_fn=os.setsid,
             **kwargs)
         pid = process.pid
         this_output, this_error = process.communicate()
@@ -889,13 +890,16 @@
     def cleanupSubprocesses(self):
         # Ensure any subprocesses are cleaned up
         for p in self.subprocesses:
-            p.terminate()
+            try:
+                os.kill(os.getpgid(p.pid), signal.SIGTERM)
+            except OSError:
+                pass
             del p
         del self.subprocesses[:]
         # Ensure any forked processes are cleaned up
         for pid in self.forkedProcessPids:
             try:
-                os.kill(pid, signal.SIGTERM)
+                os.kill(os.getpgid(pid), signal.SIGTERM)
             except OSError:
                 pass
         del self.forkedProcessPids[:]
@@ -919,8 +923,9 @@
             fd = os.open(os.devnull, os.O_RDWR)
             os.dup2(fd, 1)
             os.dup2(fd, 2)
-            # This call causes the child to have its of group ID
-            os.setpgid(0, 0)
+            # Creates a new session if the calling process is not a process
+            # group leader.
+            os.setsid()
             os.execvp(executable, [executable] + args)
         # Give the child time to get through the execvp() call
         time.sleep(0.1)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83815.277989.patch
Type: text/x-patch
Size: 1627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20200714/0942d2c0/attachment-0001.bin>


More information about the lldb-commits mailing list