Open mladedav opened 3 years ago
Tagging subscribers to this area: @eiriktsarpalis, @jeffhandley See info in area-owners.md if you want to be subscribed.
Author: | mladedav |
---|---|
Assignees: | - |
Labels: | `api-suggestion`, `area-System.Diagnostics.Process`, `untriaged` |
Milestone: | - |
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?
I believe so. That would put the new process into a new process group with ID identical to that new process' ID.
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.
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.
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:
If it's not possible, the current proposal looks as good as it is.
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).
I am affected by this as well in a very similar way to the above mentioned issue (https://github.com/pulumi/pulumi-dotnet/issues/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.
Any updates?
Background and Motivation
Creating process groups is necessary to be able to send signals on Windows as they are sent to the whole group and the calling process may not know the group ID itself. POSIX systems have the same notion, however in unix-like systems one can use signals directly with processes, which is impossible in Windows as I understand it.
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.
https://github.com/dotnet/runtime/issues/20734
Proposed API
Usage Examples
Alternative Designs
Alternative discussed in the linked issue was using creation flags such as:
But this turns somewhat Windows-centric which is not desired. Using a bool property instead is similar to how
CreateNoWindow
is exposed in ProcessStartInfo.Risks
I do not have deep knowledge on this subject but I do not see any risks. I would assume the default behavior would be kept the same so no breaking changes to existing code. I do not know of any circumstances where creating a process in new group would prevent the process from creation (such as clashing with CreateNoWindow flag), but that is potential risk. Stopping applications properly may be more challenging for developers using this as the spawned processes may not get signals generated by user interaction with terminal.