-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Add ProcessExitStatus class to System.Diagnostics.Process #124264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+125
−0
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9654755
Initial plan
Copilot 73511c6
Add ProcessExitStatus struct with API, implementation, and tests
Copilot 1754bfc
Add ProcessExitStatus to project files and fix build
Copilot b291ae1
Remove IEquatable and equality members per API review feedback
Copilot 17eaf85
Change ProcessExitStatus from struct to sealed class per API review
Copilot 2f9f9f6
Rename constructor parameter 'cancelled' to 'canceled' to match prope…
Copilot 9932cba
Clarify Signal property docs for publicly constructible type
Copilot 61b549a
Improve Signal property docs to clarify it is a Unix-only concept
Copilot 5a7c92a
Apply suggestions from code review
adamsitnik b37fd14
Remove Windows and Unix exit code remarks
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
55 changes: 55 additions & 0 deletions
55
src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessExitStatus.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
|
|
||
| namespace System.Diagnostics | ||
| { | ||
| /// <summary> | ||
| /// Represents the exit status of a process. | ||
| /// </summary> | ||
| public sealed class ProcessExitStatus | ||
| { | ||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ProcessExitStatus"/> class. | ||
| /// </summary> | ||
| /// <param name="exitCode">The exit code of the process.</param> | ||
| /// <param name="canceled">A value indicating whether the process has been terminated due to timeout or cancellation.</param> | ||
| /// <param name="signal">On Unix, the POSIX signal that terminated the process, or null if the process exited normally.</param> | ||
| public ProcessExitStatus(int exitCode, bool canceled, PosixSignal? signal = null) | ||
| { | ||
| ExitCode = exitCode; | ||
| Canceled = canceled; | ||
| Signal = signal; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the exit code of the process. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// If the process was terminated by a signal on Unix, this is 128 + the signal number. | ||
| /// Use <see cref="Signal"/> to get the actual signal. | ||
| /// </para> | ||
| /// </remarks> | ||
| public int ExitCode { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the POSIX signal that terminated the process on Unix, or <see langword="null" /> if the process was not terminated by a signal. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// On Unix, a process can be terminated by a signal (e.g., SIGKILL, SIGTERM). When this happens, | ||
| /// the kernel reports "terminated by signal X" rather than an exit code. This property captures | ||
| /// that signal. When the process exits normally on Unix, or on Windows where signals do not exist, | ||
| /// this property is <see langword="null" />. | ||
| /// </para> | ||
| /// </remarks> | ||
| public PosixSignal? Signal { get; } | ||
|
|
||
| /// <summary> | ||
| /// Gets a value indicating whether the process has been terminated due to timeout or cancellation. | ||
| /// </summary> | ||
| public bool Canceled { get; } | ||
| } | ||
| } | ||
61 changes: 61 additions & 0 deletions
61
src/libraries/System.Diagnostics.Process/tests/ProcessExitStatusTests.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
|
|
||
| namespace System.Diagnostics.Tests | ||
| { | ||
| public class ProcessExitStatusTests | ||
| { | ||
| [Fact] | ||
| public void Constructor_WithExitCodeOnly_SetsPropertiesCorrectly() | ||
| { | ||
| ProcessExitStatus status = new ProcessExitStatus(0, false); | ||
|
|
||
| Assert.Equal(0, status.ExitCode); | ||
| Assert.False(status.Canceled); | ||
| Assert.Null(status.Signal); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithNonZeroExitCode_SetsPropertiesCorrectly() | ||
| { | ||
| ProcessExitStatus status = new ProcessExitStatus(42, false); | ||
|
|
||
| Assert.Equal(42, status.ExitCode); | ||
| Assert.False(status.Canceled); | ||
| Assert.Null(status.Signal); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithCanceled_SetsPropertiesCorrectly() | ||
| { | ||
| ProcessExitStatus status = new ProcessExitStatus(1, true); | ||
|
|
||
| Assert.Equal(1, status.ExitCode); | ||
| Assert.True(status.Canceled); | ||
| Assert.Null(status.Signal); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithSignal_SetsPropertiesCorrectly() | ||
| { | ||
| ProcessExitStatus status = new ProcessExitStatus(137, false, PosixSignal.SIGTERM); | ||
|
|
||
| Assert.Equal(137, status.ExitCode); | ||
| Assert.False(status.Canceled); | ||
| Assert.Equal(PosixSignal.SIGTERM, status.Signal); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Constructor_WithAllParameters_SetsPropertiesCorrectly() | ||
| { | ||
| ProcessExitStatus status = new ProcessExitStatus(130, true, PosixSignal.SIGINT); | ||
|
|
||
| Assert.Equal(130, status.ExitCode); | ||
| Assert.True(status.Canceled); | ||
| Assert.Equal(PosixSignal.SIGINT, status.Signal); | ||
| } | ||
| } | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.