-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Enhance OSX's ProcessManager to extract process names from their paths #96287
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
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process Issue DetailsThe OSX This change improves Moreover, this update enables the retrieval of process names for which we lack privileges. For example, we can now obtain the pid and other basic information of the launchd process without elevation.
|
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Can you provide more detailed code snippet to demonstrate what problem it solves? Can there be unit test added? |
Here's a simple example: (use a project name with length greater than 15 characters) using System.Diagnostics;
Process process = Process.GetCurrentProcess();
Console.WriteLine(process.ProcessName);In this scenario, if the name of the current process exceeds 15 characters, it will be truncated. using System.Diagnostics;
Process[] processes = Process.GetProcesses();
foreach (Process process in processes)
{
Console.WriteLine($"{process.Id} - {process.ProcessName}");
}This code results in numerous system processes having an empty This limitation also affects the using System.Diagnostics;
Process[] processes = Process.GetProcessesByName("MTLCompilerService");
Console.WriteLine(processes.Length); // This will be 0, even if the process is running, due to name truncation
processes = Process.GetProcessesByName("MTLCompilerServ");
Console.WriteLine(processes.Length); // This will be greater than 0 if MTLCompilerService is runningHowever, this approach introduces uncertainty. If two processes share the same prefix but have different suffixes, it's challenging to selectively identify one over the other. using System.Diagnostics;
// Attempting to use "Bitwig Plug-in Host ARM64" returns 0 results due to truncation
Process[] armProcesses = Process.GetProcessesByName("Bitwig Plug-in ");
// Process[] intelProcesses = Process.GetProcessByName("Bitwig Plug-in "); ???
// How do we distinguish between ARM64 and X64 versions if both are present?
// We would again need to resort to manually filtering by filename, which is inconvenientThe Regarding unit tests, it's challenging to test this functionality. |
For the 15 character limitation, the test could create a new process with such name and check that and for the elevated checks, I think that iterating on all the processes on the machine will be the best option for that. |
|
There is an existing test skipped on OSX and MacCatalyst: runtime/src/libraries/System.Diagnostics.Process/tests/ProcessTests.cs Lines 2265 to 2267 in 9fa5128
Just delete line 2265 and 2267 from that file. |
I'm having a few issues getting this test to function correctly in its current form. Attempting to use a temporary script with the long name to execute the sleep command doesn't seem to resolve the issue either. This is because the process that gets executed is named bash, not the script's name. |
| // Fallback to empty string if the process name could not be retrieved | ||
| processName ??= ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fallback to pbi_comm if GetProcPath fails instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we could fall back to pbi_comm if we have the proc_taskallinfo, and otherwise just fall back to the empty string again.
I'll work on these changes 👍
I'm seeing this problem too on Sonoma. I also tried removing the signature ( |
I just tried this again but with System Integrity Protection disabled and now the copied binary works correctly |
Yes but I don't know if the OSX machines in CI run without SIP. cc @dotnet/area-infrastructure-libraries @dotnet/dnceng. |
jozkee
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks. We should address re-enabling the OSX test before 9.0 ships (#29330).
Fixes #52860.
The OSX
ProcessManagerhas been updated to extract the process name from its path, rather than relying on the 15-character-limited pbi_comm.This change improves
GetProcessByName, allowing the specification of the full process name for lookup. Additionally,Process.ProcessNamenow returns the full process name, aligning with the behavior of OSX's Activity Monitor.Moreover, this update enables the retrieval of process names for which we lack privileges. For example, we can now obtain the pid and other basic information of the launchd process without elevation.