diff --git a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs
index 4c98a461f323e..53a49f897c1a2 100644
--- a/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs
+++ b/src/libraries/System.Diagnostics.Process/ref/System.Diagnostics.Process.cs
@@ -84,7 +84,11 @@ public Process() { }
public System.DateTime StartTime { get { throw null; } }
public System.ComponentModel.ISynchronizeInvoke? SynchronizingObject { get { throw null; } set { } }
public System.Diagnostics.ProcessThreadCollection Threads { get { throw null; } }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan TotalProcessorTime { get { throw null; } }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan UserProcessorTime { get { throw null; } }
[System.ObsoleteAttribute("Process.VirtualMemorySize has been deprecated because the type of the property can't represent all valid results. Use System.Diagnostics.Process.VirtualMemorySize64 instead.")]
public int VirtualMemorySize { get { throw null; } }
@@ -106,9 +110,17 @@ public static void EnterDebugMode() { }
public static System.Diagnostics.Process GetCurrentProcess() { throw null; }
public static System.Diagnostics.Process GetProcessById(int processId) { throw null; }
public static System.Diagnostics.Process GetProcessById(int processId, string machineName) { throw null; }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcesses() { throw null; }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcesses(string machineName) { throw null; }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName) { throw null; }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public static System.Diagnostics.Process[] GetProcessesByName(string? processName, string machineName) { throw null; }
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
@@ -233,6 +245,8 @@ internal ProcessThread() { }
public int IdealProcessor { set { } }
public bool PriorityBoostEnabled { get { throw null; } set { } }
public System.Diagnostics.ThreadPriorityLevel PriorityLevel { [System.Runtime.Versioning.SupportedOSPlatform("windows")] [System.Runtime.Versioning.SupportedOSPlatform("linux")] [System.Runtime.Versioning.SupportedOSPlatform("freebsd")] get { throw null; } [System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")] set { } }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan PrivilegedProcessorTime { get { throw null; } }
[System.Runtime.Versioning.SupportedOSPlatformAttribute("windows")]
public System.IntPtr ProcessorAffinity { set { } }
@@ -241,7 +255,11 @@ public System.IntPtr ProcessorAffinity { set { } }
[System.Runtime.Versioning.SupportedOSPlatform("linux")]
public System.DateTime StartTime { get { throw null; } }
public System.Diagnostics.ThreadState ThreadState { get { throw null; } }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan TotalProcessorTime { get { throw null; } }
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("ios")]
+ [System.Runtime.Versioning.UnsupportedOSPlatformAttribute("tvos")]
public System.TimeSpan UserProcessorTime { get { throw null; } }
public System.Diagnostics.ThreadWaitReason WaitReason { get { throw null; } }
public void ResetIdealProcessor() { }
diff --git a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
index 1cb5b551f599d..27e7ac68e4af5 100644
--- a/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
+++ b/src/libraries/System.Diagnostics.Process/src/System.Diagnostics.Process.csproj
@@ -5,7 +5,6 @@
$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-FreeBSD;$(NetCoreAppCurrent)-Linux;$(NetCoreAppCurrent);$(NetCoreAppCurrent)-OSX;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOSenable
- $(NoWarn);0649SR.Process_PlatformNotSupported
@@ -325,7 +324,7 @@
-
+
@@ -346,6 +345,9 @@
+
+
+
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 02b7cce02263d..3380481ca5c8e 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
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.ComponentModel;
+using System.Runtime.Versioning;
namespace System.Diagnostics
{
@@ -12,6 +13,8 @@ public partial class Process
/// Creates an array of components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
if (processName == null)
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 6942d82d6d159..016327ad61ab5 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
@@ -7,6 +7,7 @@
using System.ComponentModel;
using System.Globalization;
using System.IO;
+using System.Runtime.Versioning;
using System.Text;
namespace System.Diagnostics
@@ -17,6 +18,8 @@ public partial class Process : IDisposable
/// Creates an array of components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
ProcessManager.ThrowIfRemoteMachine(machineName);
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs
index 897fde77e9a75..4b5f5116c14f4 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.UnknownUnix.cs
@@ -1,6 +1,8 @@
// 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.Versioning;
+
namespace System.Diagnostics
{
public partial class Process : IDisposable
@@ -9,12 +11,16 @@ public partial class Process : IDisposable
/// Creates an array of components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
throw new PlatformNotSupportedException();
}
/// Gets the amount of time the process has spent running code inside the operating system core.
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan PrivilegedProcessorTime
{
get { throw new PlatformNotSupportedException(); }
@@ -31,6 +37,8 @@ internal DateTime StartTimeCore
/// It is the sum of the and
/// .
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan TotalProcessorTime
{
get { throw new PlatformNotSupportedException(); }
@@ -40,6 +48,8 @@ public TimeSpan TotalProcessorTime
/// Gets the amount of time the associated process has spent running code
/// inside the application portion of the process (not the operating system core).
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan UserProcessorTime
{
get { throw new PlatformNotSupportedException(); }
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs
index 9c59f54333bf6..ad7209a3f198d 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs
@@ -21,6 +21,8 @@ public partial class Process : IDisposable
/// Creates an array of components that are associated with process resources on a
/// remote computer. These process resources share the specified process name.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName, string machineName)
{
if (processName == null)
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
index cb08b93c0d3e2..294ac4f2ac3f6 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
@@ -1039,6 +1039,8 @@ public static Process GetProcessById(int processId)
/// local computer. These process resources share the specified process name.
///
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcessesByName(string? processName)
{
return GetProcessesByName(processName, ".");
@@ -1050,6 +1052,8 @@ public static Process[] GetProcessesByName(string? processName)
/// component for each process resource on the local computer.
///
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcesses()
{
return GetProcesses(".");
@@ -1062,6 +1066,8 @@ public static Process[] GetProcesses()
/// process resource on the specified computer.
///
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static Process[] GetProcesses(string machineName)
{
bool isRemoteMachine = ProcessManager.IsRemoteMachine(machineName);
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs
new file mode 100644
index 0000000000000..fd1f50ccd4323
--- /dev/null
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.iOS.cs
@@ -0,0 +1,33 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Runtime.Versioning;
+
+namespace System.Diagnostics
+{
+ public partial class Process : IDisposable
+ {
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
+ public void Kill(bool entireProcessTree)
+ {
+ throw new PlatformNotSupportedException();
+ }
+
+ ///
+ /// Returns all immediate child processes.
+ ///
+ private IReadOnlyList GetChildProcesses(Process[]? processes = null)
+ {
+ throw new PlatformNotSupportedException();
+ }
+
+ private static bool IsProcessInvalidException(Exception e) =>
+ // InvalidOperationException signifies conditions such as the process already being dead.
+ // Win32Exception signifies issues such as insufficient permissions to get details on the process.
+ // In either case, the predicate couldn't be applied so return the fallback result.
+ e is InvalidOperationException || e is Win32Exception;
+ }
+}
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Unix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Unix.cs
index 5df7ece329e1d..d9e27a8c54276 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Unix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Unix.cs
@@ -3,6 +3,7 @@
using Microsoft.Win32.SafeHandles;
using System.Collections.Generic;
+using System.Runtime.Versioning;
using System.Text;
namespace System.Diagnostics
@@ -44,6 +45,8 @@ public static bool IsProcessRunning(int processId)
/// Gets the IDs of all processes on the specified machine.
/// The machine to examine.
/// An array of process IDs from the specified machine.
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static int[] GetProcessIds(string machineName)
{
ThrowIfRemoteMachine(machineName);
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs
index aa08c5b591f35..2fddb3b200e7e 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.UnknownUnix.cs
@@ -1,6 +1,8 @@
// 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.Versioning;
+
namespace System.Diagnostics
{
internal static partial class ProcessManager
@@ -14,6 +16,8 @@ public static int[] GetProcessIds()
/// Gets process infos for each process on the specified machine.
/// The target machine.
/// An array of process infos, one per found process.
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public static ProcessInfo[] GetProcessInfos(string machineName)
{
throw new PlatformNotSupportedException();
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs
index 6d947625ddd6b..acb79218a5b27 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessThread.UnknownUnix.cs
@@ -1,6 +1,8 @@
// 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.Versioning;
+
namespace System.Diagnostics
{
public partial class ProcessThread
@@ -20,6 +22,8 @@ private ThreadPriorityLevel PriorityLevelCore
/// Returns the amount of time the thread has spent running code inside the operating
/// system core.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan PrivilegedProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
@@ -32,6 +36,8 @@ public TimeSpan PrivilegedProcessorTime
/// It is the sum of the System.Diagnostics.ProcessThread.UserProcessorTime and
/// System.Diagnostics.ProcessThread.PrivilegedProcessorTime.
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan TotalProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
@@ -41,6 +47,8 @@ public TimeSpan TotalProcessorTime
/// Returns the amount of time the associated thread has spent running code
/// inside the application (not the operating system core).
///
+ [UnsupportedOSPlatform("ios")]
+ [UnsupportedOSPlatform("tvos")]
public TimeSpan UserProcessorTime
{
get { throw new PlatformNotSupportedException(); } // Not available on POSIX
diff --git a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ThreadInfo.cs b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ThreadInfo.cs
index c12c143e5a53a..1205e732e6732 100644
--- a/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ThreadInfo.cs
+++ b/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ThreadInfo.cs
@@ -12,6 +12,7 @@ namespace System.Diagnostics
///
internal sealed class ThreadInfo
{
+#pragma warning disable CS0649 // The fields are unused on iOS/tvOS as the respective managed logic (mostly around libproc) is excluded.
internal ulong _threadId;
internal int _processId;
internal int _basePriority;
@@ -19,5 +20,6 @@ internal sealed class ThreadInfo
internal IntPtr _startAddress;
internal ThreadState _threadState;
internal ThreadWaitReason _threadWaitReason;
+#pragma warning restore CS0649
}
}
diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs
index 33f84717da719..fd4e9d2751753 100644
--- a/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs
+++ b/src/libraries/System.Diagnostics.Process/tests/ProcessModuleTests.cs
@@ -10,6 +10,7 @@ namespace System.Diagnostics.Tests
public partial class ProcessModuleTests : ProcessTestBase
{
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void TestModuleProperties()
{
ProcessModuleCollection modules = Process.GetCurrentProcess().Modules;
@@ -29,6 +30,7 @@ public void TestModuleProperties()
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void Modules_Get_ContainsHostFileName()
{
ProcessModuleCollection modules = Process.GetCurrentProcess().Modules;
diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
index 8845803d08086..b3086da60d757 100644
--- a/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
+++ b/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs
@@ -414,6 +414,7 @@ public void TestExitTime()
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void StartTime_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
@@ -525,6 +526,7 @@ public void MachineName_GetNotStarted_ThrowsInvalidOperationException()
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void TestMainModule()
{
Process p = Process.GetCurrentProcess();
@@ -854,6 +856,7 @@ public void TotalProcessorTime_PerformLoop_TotalProcessorTimeValid()
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void UserProcessorTime_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
@@ -861,6 +864,7 @@ public void UserProcessorTime_GetNotStarted_ThrowsInvalidOperationException()
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void PriviledgedProcessorTime_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
@@ -868,6 +872,7 @@ public void PriviledgedProcessorTime_GetNotStarted_ThrowsInvalidOperationExcepti
}
[Fact]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void TotalProcessorTime_GetNotStarted_ThrowsInvalidOperationException()
{
var process = new Process();
@@ -1105,7 +1110,7 @@ public void TestGetProcessById()
}
[Fact]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/60588", TestPlatforms.iOS | TestPlatforms.tvOS)]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void TestGetProcesses()
{
Process currentProcess = Process.GetCurrentProcess();
@@ -1171,7 +1176,7 @@ public void GetProcesses_RemoteMachinePath_ReturnsExpected()
}
[Fact]
- [ActiveIssue("https://github.com/dotnet/runtime/issues/60588", TestPlatforms.iOS | TestPlatforms.tvOS)]
+ [SkipOnPlatform(TestPlatforms.iOS | TestPlatforms.tvOS, "libproc is not supported on iOS/tvOS")]
public void GetProcessesByName_ProcessName_ReturnsExpected()
{
// Get the current process using its name
@@ -1231,7 +1236,7 @@ public static IEnumerable