diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs
index eeac5579c180c0..97c0b27c730982 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.BSD.cs
@@ -57,6 +57,8 @@ private static IntPtr ProcessorAffinityCore
///
private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorkingSet)
{
+ EnsureState(State.HaveNonExitedId);
+
// We can only do this for the current process on OS X
if (_processId != Environment.ProcessId)
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
@@ -86,6 +88,8 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
/// The resulting maximum working set limit after any changes applied.
private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
{
+ EnsureState(State.HaveNonExitedId);
+
// We can only do this for the current process on OS X
if (_processId != Environment.ProcessId)
throw new PlatformNotSupportedException(SR.OsxExternalProcessWorkingSetNotSupported);
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
index cf5ceb58e831cc..3c707d7473bcd9 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Linux.cs
@@ -246,8 +246,9 @@ private void GetWorkingSetLimits(out IntPtr minWorkingSet, out IntPtr maxWorking
/// The resulting minimum working set limit after any changes applied.
/// The resulting maximum working set limit after any changes applied.
#pragma warning disable IDE0060
- private static void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
+ private void SetWorkingSetLimitsCore(IntPtr? newMin, IntPtr? newMax, out IntPtr resultingMin, out IntPtr resultingMax)
{
+ EnsureState(State.HaveNonExitedId);
// RLIMIT_RSS with setrlimit not supported on Linux > 2.4.30.
throw new PlatformNotSupportedException(SR.MinimumWorkingSetNotSupported);
}
diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
index 6907a43b630400..56d3a68bacb660 100644
--- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
+++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
@@ -603,20 +603,12 @@ public void TestMaxWorkingSet()
}
[Fact]
- [SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MaxWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
public void MaxWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws(() => process.MaxWorkingSet);
- }
-
- [Fact]
- [PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
- public void MaxValueWorkingSet_GetSetMacos_ThrowsPlatformSupportedException()
- {
- var process = new Process();
- Assert.Throws(() => process.MaxWorkingSet);
- Assert.Throws(() => process.MaxWorkingSet = (IntPtr)1);
+ Assert.Throws(() => process.MaxWorkingSet = (IntPtr)1);
}
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
@@ -659,21 +651,13 @@ public void TestMinWorkingSet()
}
[Fact]
- [SkipOnPlatform(TestPlatforms.OSX | TestPlatforms.FreeBSD | TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on OSX, BSD, iOS, MacCatalyst, and tvOS.")]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.MacCatalyst | TestPlatforms.tvOS, "Getting MinWorkingSet is not supported on iOS, MacCatalyst, and tvOS.")]
public void MinWorkingSet_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
Assert.Throws(() => process.MinWorkingSet);
}
- [Fact]
- [PlatformSpecific(TestPlatforms.OSX | TestPlatforms.FreeBSD)]
- public void MinWorkingSet_GetMacos_ThrowsPlatformSupportedException()
- {
- var process = new Process();
- Assert.Throws(() => process.MinWorkingSet);
- }
-
[Fact]
public void TestModules()
{