Open
Description
Background and motivation
dotnet-watch needs to be able to terminate process gracefully, i.e. give it a chance to clean up resources.
On Windows this API would call GenerateConsoleCtrlEvent
, on Unix it would send SIGTERM signal.
Currently this requires reimplementing both process creation and termination using P/Invokes.
API Proposal
Multiple options. One option is to add parameter to Process.Kill
that indicates whether we want forced kill or "soft" termination (Ctrl+C/SIGTERM).
Process.Kill(bool entireProcessTree, bool forced = true);
ProcessStartInfo might need a bool property, say EnableConsoleControlEvents
that allows Kill to send Ctrl+C.
API Usage
var process = new Process
{
StartInfo =
{
EnableConsoleControlEvents = true
// file name, arguments, output redirection, etc.
}
};
process.Start();
process.Kill(entireProcessTree: false, forced: false);
process.WaitForExit();
Alternative Designs
Related: #71515
Risks
No response