Replace ProcessUtilities.SendPosixSignal with SafeProcessHandle.Signal API#53920
Merged
adamsitnik merged 7 commits intomainfrom Apr 27, 2026
Merged
Conversation
…l API Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/2dde12c1-cfc0-4e30-800d-a69e11403c37 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
…onsole Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/2dde12c1-cfc0-4e30-800d-a69e11403c37 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
adamsitnik
April 16, 2026 14:19
View session
adamsitnik
reviewed
Apr 16, 2026
Member
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Agent-Logs-Url: https://github.com/dotnet/sdk/sessions/e8f0aa51-b60f-48ca-a7d6-c6eb548dbec0 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
This was referenced Apr 16, 2026
Open
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates dotnet-watch’s Unix process termination from a custom kill P/Invoke (ProcessUtilities.SendPosixSignal) to the newer SafeProcessHandle.Signal(PosixSignal) API, aligning the implementation with the runtime-provided signaling mechanism.
Changes:
- Remove the
SendPosixSignalP/Invoke wrapper and related SIG* constants fromProcessUtilities. - Update
ProcessRunnerto signal the existingProcessviaprocess.SafeHandle.Signal(...)on Unix. - Update
PhysicalConsoleto resolve processes by PID (Process.GetProcessById) in order to obtain aSafeHandlefor signaling.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/Dotnet.Watch/Watch/Utilities/ProcessUtilities.cs | Removes the custom kill P/Invoke signal-sending helper and constants, leaving only the Windows Ctrl+C path. |
| src/Dotnet.Watch/Watch/UI/PhysicalConsole.cs | Uses Process.GetProcessById(...).SafeHandle.Signal(PosixSignal.SIGTERM) to propagate Ctrl+C/SIGTERM behavior to child processes on Unix. |
| src/Dotnet.Watch/Watch/Process/ProcessRunner.cs | Uses process.SafeHandle.Signal(...) for Unix termination, and adds platform annotation to satisfy platform compatibility analysis. |
tmat
approved these changes
Apr 27, 2026
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Migrate from the manual P/Invoke
killwrapper (ProcessUtilities.SendPosixSignal) to the newSafeProcessHandle.Signal(PosixSignal)API introduced in dotnet/runtime#126313.Changes
ProcessRunner.cs:TerminateUnixProcessnow takes aProcessand callsprocess.SafeHandle.Signal(PosixSignal.SIGKILL / SIGTERM). Annotated[UnsupportedOSPlatform("windows")]to satisfy CA1416.PhysicalConsole.cs: Resolves process by ID viaProcess.GetProcessByIdto obtain a handle forSignal. CatchesArgumentExceptionfor already-exited processes.ProcessUtilities.cs: RemovedSendPosixSignal,SIGKILL, andSIGTERMconstants.SendWindowsCtrlCEventremains.Before:
After: