Skip to content

Add CreateNewProcessGroup to ProcessStartInfo #44944

@mladedav

Description

@mladedav

Background and Motivation

Edited by @jozkee

Creating process groups is necessary to be able to send signals on Windows as they are sent to the whole group, you need to use CREATE_NEW_PROCESS_GROUP creation flag to isolate the signal from the parent process. POSIX systems have the same notion, however in unix-like systems one can use signals directly with processes.

This has been previously discussed in another issue in 2017 but it turned out that this change itself would not help the requesting team so it was dropped at that time. For the record, I am using proposals from that time.

#20734

Proposed API

Expose the creation flag via a Windows-only property.

namespace System.Diagnostics
{
     public sealed partial class ProcessStartInfo
     {
+          [SupportedOSPlatform("windows")]
+          public bool CreateNewProcessGroup { get; set; }
     }
}

Usage Examples

var startInfo = new ProcessStartInfo
{
    FileName = "my-program.exe",
    CreateNewProcessGroup = true,
};
var p = new Process.Start(startInfo);
// Do some work...

GenerateConsoleCtrlEvent(0 /* CTRL_C_EVENT */, (uint)process.Id)

[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GenerateConsoleCtrlEvent(uint dwCtrlEvent, uint dwProcessGroupId);

Alternative Designs

  1. [API Proposal]: ProcessStartInfo.CreationFlags (for Windows only) #71515 was considered but I've opted for this proposal instead as we do have concrete scenarios for it.

  2. [API Proposal]: Add API to gracefully terminate process #109432, diffrent property naming: EnableConsoleControlEvents. This name makes sense if CREATE_NEW_PROCESS_GROUP has no other reason to be used for, outside of signal isolation, I'm unaware of more scenarios where this is useful but that can change in the future.

Risks

None

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Diagnostics.ProcessblockingMarks issues that we want to fast track in order to unblock other important workin-prThere is an active PR which will close this issue when it is mergedos-windows

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions