Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions src/tests/Common/Coreclr.TestWrapper/CoreclrTestWrapperLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,15 +681,25 @@ public static bool TryPrintStackTraceFromDmp(string dmpFile, TextWriter outputWr
// The children are sorted in the order they should be dumped
static unsafe IEnumerable<Process> FindChildProcessesByName(Process process, string childName)
{
Console.WriteLine($"Finding all child processes of '{process.ProcessName}' (ID: {process.Id}) with name '{childName}'");
process.TryGetProcessName(out string parentProcessName);
process.TryGetProcessId(out int parentProcessId);
Console.WriteLine($"Finding all child processes of '{parentProcessName}' (ID: {parentProcessId}) with name '{childName}'");

var children = new Stack<Process>();
Queue<Process> childrenToCheck = new Queue<Process>();
HashSet<int> seen = new HashSet<int>();

seen.Add(process.Id);
foreach (var child in process.GetChildren())
childrenToCheck.Enqueue(child);
seen.Add(parentProcessId);

try
{
foreach (var child in process.GetChildren())
childrenToCheck.Enqueue(child);
}
catch
{
// Process exited
}

while (childrenToCheck.Count != 0)
{
Expand All @@ -707,8 +717,15 @@ static unsafe IEnumerable<Process> FindChildProcessesByName(Process process, str
Console.WriteLine($"Checking child process: '{processName}' (ID: {processId})");
seen.Add(processId);

foreach (var grandchild in child.GetChildren())
childrenToCheck.Enqueue(grandchild);
try
{
foreach (var grandchild in child.GetChildren())
childrenToCheck.Enqueue(grandchild);
}
catch
{
// Process exited
}

if (processName.Equals(childName, StringComparison.OrdinalIgnoreCase))
{
Expand Down Expand Up @@ -844,7 +861,9 @@ public int RunTest(string executable, string outputFile, string errorFile, strin
Console.WriteLine($"\t{"ID",-6} ProcessName");
foreach (var activeProcess in Process.GetProcesses())
{
Console.WriteLine($"\t{activeProcess.Id,-6} {activeProcess.ProcessName}");
activeProcess.TryGetProcessName(out string activeProcessName);
activeProcess.TryGetProcessId(out int activeProcessId);
Console.WriteLine($"\t{activeProcessId,-6} {activeProcessName}");
}

if (OperatingSystem.IsWindows())
Expand Down