Skip to content

Implement SafeProcessHandle.WaitForExit* methods#127022

Merged
adamsitnik merged 24 commits into
mainfrom
copilot/implement-issue-126293
Apr 22, 2026
Merged

Implement SafeProcessHandle.WaitForExit* methods#127022
adamsitnik merged 24 commits into
mainfrom
copilot/implement-issue-126293

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 16, 2026

Implements the approved SafeProcessHandle.WaitForExit* API surface from #123380.

Description

Adds 5 new public methods to SafeProcessHandle: WaitForExit, TryWaitForExit, WaitForExitOrKillOnTimeout, WaitForExitAsync, and WaitForExitOrKillOnCancellationAsync.

Key changes

  • Shared async logic in SafeProcessHandle.cs using RegisterWaitForSingleObject + TaskCompletionSource
  • Windows: Uses ProcessWaitHandle + GetExitCodeProcess for synchronous wait and exit code retrieval
  • Unix: Integrates with ProcessWaitState for reaping coordination; ProcessId property moved to platform-specific file and reads from _waitStateHolder._state._processId
  • Native PAL: WaitPidExitedNoHang now returns terminating signal info via TryConvertSignalCodeToPosixSignal
  • ProcessWaitState: Stores ProcessExitStatus? instead of separate _exitCode/_terminatingSignal fields; added Holder.IncrementRefCount() for ref-counted ownership sharing between Process and SafeProcessHandle
  • Process.Unix.cs: GetProcessHandle() and StartCore use IncrementRefCount() pattern for proper wait state holder ownership
  • Consistency fix: Both ProcessId and GetWaitState() now throw InvalidOperationException when _waitStateHolder is null (previously ProcessId threw PlatformNotSupportedException); GetWaitState() throws PlatformNotSupportedException for non-child processes on Unix
  • Ref assembly: Updated with new API surface
  • Tests: Comprehensive WaitForExit* tests including sync/async theories, signal reporting, timeout/kill behavior, non-child process handling, and Process.SafeHandle interop

Loading
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement SafeProcessHandle.WaitForExit* methods

5 participants