Uh oh!
There was an error while loading. Please reload this page.
Implement SafeProcessHandle.Open/TryOpen and Process.TryGetProcessById - #126705
Conversation
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f57caa85-c528-444f-ab43-a628d6ddd488 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/f57caa85-c528-444f-ab43-a628d6ddd488 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot give my feedback a try. Run all process tests and ensure they pass before you push any changes.
Uh oh!
There was an error while loading. Please reload this page.
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process |
…ss with outPidfd parameter Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/664957d4-993f-4f40-aa79-ce45ec55fd11 Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…acOS posix_spawn path Agent-Logs-Url: https://github.com/dotnet/runtime/sessions/ed9ebae7-b0ac-4a66-a222-8f7305c55a9b Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
…SystemNative_OpenProcess with waitid EPERM fallback Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Addressed in the latest commit:
|
…xactly what Process.GetProcessById does
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
tmds
commented
Jun 2, 2026
@adamsitnikhttps://github.com/dotnet/runtime/pull/126705/changes#r3328152606 was marked as resolved. Did you see my open question? |
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
commented
Jun 3, 2026
I've missed your last question, marked as unresolved and provided my context |
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
adamsitnik
left a comment
There was a problem hiding this comment.
@copilot please address my feedback
Co-authored-by: adamsitnik <6011991+adamsitnik@users.noreply.github.com>
Addressed in Note AI-generated content disclosure: this response was generated with AI assistance. |
Summary
Implements the
SafeProcessHandle.Open(int processId)andSafeProcessHandle.TryOpen(int processId, out SafeProcessHandle? handle)APIs for opening an existing process by ID, and addsProcess.TryGetProcessById.Also incorporates follow-up fixes for Unix/Windows error handling, API consistency, and API documentation clarity (especially the differences between
SafeProcessHandle.[Try]OpenandProcess.GetProcessById(...).SafeHandle/Process.TryGetProcessById).APIs approved in #123380 (comment) and #101582 (comment).
Changes
Native layer (
pal_process.c,pal_process_wasi.c,pal_process.h,entrypoints.c):SystemNative_OpenProcessand related native/export plumbing#include <sys/syscall.h>from theHAVE_CLOSE_RANGEbranchForkAndExecOnPDeathSigThreadcall to return directlyManaged layer:
SafeProcessHandle.Unix.cs:TryOpenCoreusesInterop.Sys.Kill(processId, 0)directlySafeProcessHandle.Unix.cs:TryOpenCoreusesInterop.Sys.GetLastErrorInfo()(compare via.Error, propagate.RawErrno) so Unix error reporting maps correctlySafeProcessHandle.Unix.cs/SafeProcessHandle.Windows.cs: access-denied behavior unified via sharedThrowOpenProcessAccessDeniedExceptionSafeProcessHandle.Windows.cs:OpenCoreusesOpenProcesswithPROCESS_QUERY_LIMITED_INFORMATION | SYNCHRONIZE | PROCESS_TERMINATESafeProcessHandle.cs:Open(int processId)validates arguments, callsTryOpenCorewithout int lastError, and throws using returned errorTryOpenCoreon both platforms returnsfalseonly for not-found/invalid-parameter conditions; other failures throwProcess.cs:TryGetProcessByIdvalidates arguments and aligns with existingGetProcessByIdsemantics by checkingProcessManager.IsProcessRunningand returning aProcessinstance without eagerly opening a handleInterop.Sys.OpenProcessInterop.ForkAndExecProcess.cs:inheritedHandlesparameter has defaultnullSafeProcessHandle.Open/SafeProcessHandle.TryOpento explicitly document behavioral differences fromProcess.GetProcessById(...).SafeHandleandProcess.TryGetProcessByIdTests:
[Theory]Open_ExitedProcess_WorksAsLongAsAtLeastOneHandleIsOpenGetProcessById_KilledProcess_ThrowsArgumentExceptioninProcessTests.csAssert.NotNull(handle)inProcessOpenTestsbefore dereferencing nullable handleTesting
System.Diagnostics.Process.Teststotal 627, failed 0, skipped 2System.Diagnostics.Process.Teststotal 625, failed 0, skipped 6./build.sh libs.native -c Debug -os linux -arch x64✅./dotnet.sh build src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj -c Debug /p:TargetOS=linux /p:TargetArchitecture=x64✅./build.sh clr+libs+host -rc release -lc release✅./dotnet.sh build src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj -c Debug /p:TargetOS=linux /p:TargetArchitecture=x64✅./dotnet.sh build /t:test src/libraries/System.Diagnostics.Process/tests/System.Diagnostics.Process.Tests.csproj -c Release /p:TargetOS=linux /p:TargetArchitecture=x64✅ (Total: 628, Failed: 0, Skipped: 6)