[英]Reduce threads to reduce CPU usage of powershell process through powershell command
我在 powershell 中使用了一个 Fake cpu 使用脚本,当我运行它时,CPU 使用率会增加,我可以看到线程数。 现在我必须减少/增加线程数以减少 CPU 使用率。 下面是用于增加 CPU 使用率的脚本。 请帮助使用任何可以减少/增加线程数以减少 CPU 使用率的 powershell 命令。 或任何其他减少此脚本中 CPU 使用率的方法。 下面是循环脚本的主要部分,通过在 powershell 中运行它会增加 CPU 使用率
# Code
$num = 2
If ([$num -gt 1])) {
$ThreadCount=(Get-Process -ProcessName Powershell | Select-Object -ExpandProperty Threads).Count
$ErrorMessage = "Before CPU Saturation threadcount:" + $ThreadCount
write-AppEventLog $ErrorMessage
$result = 1;
foreach ($number in 1..2147483647) {
$ThreadCount1=(Get-Process -ProcessName Powershell | Select-Object -ExpandProperty Threads).Count
foreach ($number in 1..2147483647) {
$result = $result * $number
$ErrorMessage1 = " CPU Saturation threadcount:" + $ThreadCount1
write-AppEventLog $ErrorMessage1
}
}
}
如果你想要多个线程,你可以使用jobs
Start-Job -ScriptBlock {
# do the thing
}
# Example infinite loop
while($true)
{
Start-Job -ScriptBlock {
# do the thing
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.