如何利用PowerShell来监控一个进程实际产生了多少个线程
$processName = "chrome.exe"
$process = Get-WmiObject -Query "SELECT * FROM Win32_Process WHERE Name='$processName'"
$threadCount = $process.ThreadCount
Write-Host "The number of threads in $processName is $threadCount"
其中$processName 是实际的进程名称,
以这个为例,我实际得到的结果是
The number of threads in chrome.exe is 47 7 39 14 10 9 23 27 14
那么实际的线程数量应该是 47+7+39+14+10+9+23+27+14=190
如何利用代码来监控一个进程实际产生了多少个线程
int threadCount = 0;
string processName = "chrome";
Process[] processes = Process.GetProcessesByName(processName);
foreach (var item in processes)
{
threadCount += item.Threads.Count;
}