From e1082c9fa8763696ea87c75b1435db9d3a2e1d7c Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Wed, 27 Mar 2002 18:36:37 +0000
Subject: [PATCH] added wxEXEC_MAKE_GROUP_LEADER (patch 535422)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14819 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex |  6 ++++++
 include/wx/utils.h         | 17 +++++++++++++----
 src/unix/utilsunx.cpp      |  7 +++++++
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 9fe55f3bf6..0b3248160c 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -480,6 +480,12 @@ flush an unnecessary console for the processes which don't create any windows
 anyhow) but a {\tt wxEXEC\_NOHIDE} flag can be used to prevent this from
 happening, i.e. with this flag the child process window will be shown normally.
 
+Under Unix the flag {\tt wxEXEC\_MAKE\_GROUP\_LEADER} may be used to ensure
+that the new process is a group leader (this will create a new session if
+needed). Calling \helpref{wxKill}{wxkill} with the argument of -pid where pid
+is the process ID of the new process will kill this process as well as all of
+its children (except those which have started their own session).
+
 Finally, you may use the third overloaded version of this function to execute
 a process (always synchronously) and capture its output in the array
 {\it output}. The fourth version adds the possibility to additionally capture
diff --git a/include/wx/utils.h b/include/wx/utils.h
index 2306a14cd3..f8c883eb08 100644
--- a/include/wx/utils.h
+++ b/include/wx/utils.h
@@ -153,10 +153,19 @@ WXDLLEXPORT wxString wxDecToHex(int dec);
 
 enum
 {
-    wxEXEC_ASYNC    = 0,    // execute the process asynchronously
-    wxEXEC_SYNC     = 1,    //                     synchronously
-    wxEXEC_NOHIDE   = 2     // under Windows, don't hide the child even if it's
-                            // IO is redirected (this is done by default)
+    // execute the process asynchronously
+    wxEXEC_ASYNC    = 0,
+
+    // execute it synchronously, i.e. wait until it finishes
+    wxEXEC_SYNC     = 1,
+
+    // under Windows, don't hide the child even if it's IO is redirected (this
+    // is done by default)
+    wxEXEC_NOHIDE   = 2,
+
+    // under Unix, if the process is the group leader then killing -pid kills
+    // all children as well as pid
+    wxEXEC_MAKE_GROUP_LEADER = 4
 };
 
 // Execute another program.
diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp
index 83e04373a4..8d1c888fc7 100644
--- a/src/unix/utilsunx.cpp
+++ b/src/unix/utilsunx.cpp
@@ -650,6 +650,13 @@ long wxExecute(wxChar **argv,
                 if ( fd != STDERR_FILENO )
                     close(fd);
             }
+
+            if ( flags & wxEXEC_MAKE_GROUP_LEADER )
+            {
+                // Set process group to child process' pid.  Then killing -pid
+                // of the parent will kill the process and all of its children.
+                setsid();
+            }
         }
 
         // redirect stdio, stdout and stderr
-- 
2.50.0

