Skip to content

Commit 14a2995

Browse files
authored
Remove process suspend (#4586)
1 parent 09027e2 commit 14a2995

File tree

1 file changed

+5
-37
lines changed

1 file changed

+5
-37
lines changed

src/Microsoft.TestPlatform.Extensions.BlameDataCollector/ProcessCodeMethods.cs

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public static void Suspend(this Process process)
3131

3232
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3333
{
34-
SuspendWindows(process);
34+
// There is no supported or documented API to suspend a process. If there was you should call it here.
35+
// SuspendWindows(process);
3536
}
3637
else
3738
{
@@ -70,40 +71,6 @@ public static List<ProcessTreeNode> GetProcessTree(this Process process)
7071
return new List<ProcessTreeNode> { new ProcessTreeNode { Process = process, Level = 0 } }.Concat(acc.Where(a => a.Level > 0)).ToList();
7172
}
7273

73-
internal static void SuspendWindows(Process process)
74-
{
75-
EqtTrace.Verbose($"ProcessCodeMethods.Suspend: Suspending process {process.Id} - {process.ProcessName}.");
76-
NtSuspendProcess(process.Handle);
77-
}
78-
79-
internal static void SuspendLinuxMacOs(Process process)
80-
{
81-
try
82-
{
83-
var output = new StringBuilder();
84-
var err = new StringBuilder();
85-
Process ps = new();
86-
ps.StartInfo.FileName = "kill";
87-
ps.StartInfo.Arguments = $"-STOP {process.Id}";
88-
ps.StartInfo.UseShellExecute = false;
89-
ps.StartInfo.RedirectStandardOutput = true;
90-
ps.OutputDataReceived += (_, e) => output.Append(e.Data);
91-
ps.ErrorDataReceived += (_, e) => err.Append(e.Data);
92-
ps.Start();
93-
ps.BeginOutputReadLine();
94-
ps.WaitForExit(5_000);
95-
96-
if (!err.ToString().IsNullOrWhiteSpace())
97-
{
98-
EqtTrace.Verbose($"ProcessCodeMethods.SuspendLinuxMacOs: Error suspending process {process.Id} - {process.ProcessName}, {err}.");
99-
}
100-
}
101-
catch (Exception ex)
102-
{
103-
EqtTrace.Verbose($"ProcessCodeMethods.GetParentPidMacOs: Error getting parent of process {process.Id} - {process.ProcessName}, {ex}.");
104-
}
105-
}
106-
10774
/// <summary>
10875
/// Returns the parent id of a process or -1 if it fails.
10976
/// </summary>
@@ -248,6 +215,7 @@ private static extern int NtQueryInformationProcess(
248215
int processInformationLength,
249216
out int returnLength);
250217

251-
[DllImport("ntdll.dll", SetLastError = true)]
252-
private static extern IntPtr NtSuspendProcess(IntPtr processHandle);
218+
// This call is undocumented api, and should not be used.
219+
//[DllImport("ntdll.dll", SetLastError = true)]
220+
//private static extern IntPtr NtSuspendProcess(IntPtr processHandle);
253221
}

0 commit comments

Comments
 (0)