Skip to content

Add CreateNewProcessGroup to ProcessStartInfo #44944

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

Activity

  1. added
    api-suggestionEarly API idea and discussion, it is NOT ready for implementation
    on Nov 19, 2020
  2. eiriktsarpalis commented on Nov 20, 2020

    @eiriktsarpalis
    Member

    If I get this correctly, in order to obtain the same behaviour as CREATE_NEW_PROCESS_GROUP on Unix we would need to call setpgid(0, 0); between fork and execve?

  3. mladedav commented on Nov 23, 2020

    @mladedav
    Author

    I believe so. That would put the new process into a new process group with ID identical to that new process' ID.

  4. eiriktsarpalis commented on Nov 23, 2020

    @eiriktsarpalis
    Member

    My concern about this proposal is that it seems to only allow a very constrained use case for process groups. What if I wanted to create a process group that includes the current process?

    It is probably telling that in the original issue it was determined that ProcessStartInfo is probably not the appropriate API for making this type of configuration. So if we can't provide a general-purpose solution here, perhaps we shouldn't be adding it at all.

  5. mladedav commented on Nov 23, 2020

    @mladedav
    Author

    As I understand the comment, ProcessStartInfo wasn't appropriate for the advanced usage PaulHigin needed, not for the flag itself. I can't think of a better place for this since this needs to be set before the process is started, but I do not mind it being anywhere else.

    The constraints are based on what both Windows and Linux can do - Windows only has a flag CREATE_NEW_PROCESS_GROUP for CreaetProcess* functions while Linux is able to change the group ID dynamically after fork.

    If you want the new process to be part of the creating process' group, you simply don't specify the option, it is the default in both OSs.

  6. adamsitnik commented on Nov 26, 2020

    @adamsitnik
    Member

    Triage:

    We should do research and find out if Windows allows for modifying process group after process creation as Unix does. If it does, we should consider adding APIs for all possibilities:

    • getting and setting process group of a given process instance
    • specify it during creating

    If it's not possible, the current proposal looks as good as it is.

  7. added
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 26, 2020
  8. Tyrrrz commented on Feb 8, 2021

    @Tyrrrz
    Contributor

    Note: as @mladedav initially pointed out, the primary goal of this feature is to allow sending signals to the process on Windows.
    If Process somehow exposed this functionality directly (e.g. with a process.SendSignal(...) method), then this switch would not be needed and may become an implementation detail (i.e. Process.Start(...) may still create a new process group, just not expose it to the caller).

  9. added this to the Future milestone on Jul 13, 2021
  10. ItsRevolt commented on Dec 24, 2023

    @ItsRevolt

    I am affected by this as well in a very similar way to the above mentioned issue (pulumi/pulumi-dotnet#124)

    Wanted to comment on this just to show there is a want for this, as the previous issue was closed due to lack of use by devs.

  11. lennybacon commented on May 10, 2024

    @lennybacon

    Any updates?

  12. 2 remaining items

  13. added
    blockingMarks issues that we want to fast track in order to unblock other important work
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    and removed
    needs-further-triageIssue has been initially triaged, but needs deeper consideration or reconsideration
    on Jun 26, 2025
  14. modified the milestones: Future, 10.0.0 on Jun 26, 2025
  15. added theissue type on Jun 26, 2025
  16. jilles-sg commented on Jun 26, 2025

    @jilles-sg

    We should do research and find out if Windows allows for modifying process group after process creation as Unix does. If it does, we should consider adding APIs for all possibilities:

    * getting and setting process group of a given process instance
    
    * specify it during creating
    

    Please note the restriction on modifying the process group of an existing other process using setpgid: this can only be done if the target process has not called execve or a similar function yet. In fact, that form of the call is only intended to allow the parent process to ensure the process group has been set in the absence of other synchronization (such as the pipe .NET uses to obtain the return value from execve). The child process should always set its own process group ID (if the parent's process group ID is unsuitable). If the parent process encounters the error condition [EACCES] that the target process has already called execve, the process group has already been set, so the parent process needs to ignore the error.

    Instead, the extra possibilities of setpgid are for two use cases:

    • Create multiple child processes and have all of them join a single new process group. Most job control shells such as bash and zsh do this for pipelines. This allows all elements of a pipeline access to the terminal while also allowing the shell to wait for and check the exit status of all elements, and not creating any additional processes.
    • In a job control shell, set the shell's process group ID to the shell's process ID, and attempt to undo that when disabling job control mode (such as when suspending the shell itself). If someone wants to do this from .NET, I'd say platform invoke is fine.

    Documentation should warn that starting a process in a new process group may have unexpected effects if the process has a controlling terminal. In particular, the child process will not receive signals from key combinations such as Ctrl+C and will be suspended if it tries to read from the terminal (the kernel assuming that the parent process will deal with that).

    If the process does not have a controlling terminal, creating new process groups is fine and allows sending signals to whole trees of processes except those that actively change their process group ID.

    If Windows provides no way to create multiple child processes and have all of them join a single new process group, the CreateNewProcessGroup boolean is certainly sufficient.

  17. jozkee commented on Jun 26, 2025

    @jozkee
    Member

    @jilles-sg I updated the API proposal yesterday to reflect this will be a Windows-only API to unblock sending signals to an isolated process group. There won't be any effects in Unix.

  18. added
    in-prThere is an active PR which will close this issue when it is merged
    on Jun 27, 2025
  19. bartonjs commented on Jul 1, 2025

    @bartonjs
    Member

    Video

    Looks good as proposed

    namespace System.Diagnostics
    {
        public sealed partial class ProcessStartInfo
        {
            [SupportedOSPlatform("windows")]
            public bool CreateNewProcessGroup { get; set; }
        }
    }
  20. added
    api-approvedAPI was approved in API review, it can be implemented
    and removed
    api-ready-for-reviewAPI is ready for review, it is NOT ready for implementation
    on Jul 1, 2025
  21. locked and limited conversation to collaborators on Aug 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions