@@ -164,6 +164,9 @@ public final class Process: ObjectIdentifierProtocol {
164
164
/// Queue to protect reading/writing on map of validated executables.
165
165
private static let executablesQueue = DispatchQueue (
166
166
label: " org.swift.swiftpm.process.findExecutable " )
167
+
168
+ /// Indicates if a new progress group is created for the child process.
169
+ private let startNewProcessGroup : Bool
167
170
168
171
/// Cache of validated executables.
169
172
///
@@ -180,16 +183,20 @@ public final class Process: ObjectIdentifierProtocol {
180
183
/// - redirectOutput: Redirect and store stdout/stderr output (of subprocess) in the process result, instead of
181
184
/// printing on the standard streams. Default value is true.
182
185
/// - verbose: If true, launch() will print the arguments of the subprocess before launching it.
186
+ /// - startNewProcessGroup: If true, a new progress group is created for the child making it
187
+ /// continue running even if the parent is killed or interrupted. Default value is true.
183
188
public init (
184
189
arguments: [ String ] ,
185
190
environment: [ String : String ] = env,
186
191
redirectOutput: Bool = true ,
187
- verbose: Bool = Process . verbose
192
+ verbose: Bool = Process . verbose,
193
+ startNewProcessGroup: Bool = true
188
194
) {
189
195
self . arguments = arguments
190
196
self . environment = environment
191
197
self . redirectOutput = redirectOutput
192
198
self . verbose = verbose
199
+ self . startNewProcessGroup = startNewProcessGroup
193
200
}
194
201
195
202
/// Returns the path of the the given program if found in the search paths.
@@ -268,12 +275,13 @@ public final class Process: ObjectIdentifierProtocol {
268
275
posix_spawnattr_setsigdefault ( & attributes, & mostSignals)
269
276
#endif
270
277
271
- // Establish a separate process group.
272
- posix_spawnattr_setpgroup ( & attributes, 0 )
273
-
274
278
// Set the attribute flags.
275
279
var flags = POSIX_SPAWN_SETSIGMASK | POSIX_SPAWN_SETSIGDEF
276
- flags |= POSIX_SPAWN_SETPGROUP
280
+ if startNewProcessGroup {
281
+ // Establish a separate process group.
282
+ flags |= POSIX_SPAWN_SETPGROUP
283
+ posix_spawnattr_setpgroup ( & attributes, 0 )
284
+ }
277
285
278
286
posix_spawnattr_setflags ( & attributes, Int16 ( flags) )
279
287
0 commit comments