如何将任务列表的 CPU 时间转换为 CPU 使用百分比?
我正在尝试使用 tasklist
找出哪个进程消耗了超过 X% 的 CPU(稍后用 taskkill
杀死它)。
我如何知道百分比是多少时间格式代表什么?
文件说:
TASKLIST options
/FI filter
一个过滤器可能是:
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format: hh:mm:ss.
hh - number of hours,
mm - minutes, ss - seconds
如果我尝试
tasklist /FI "CPUTIME gt 00:00:10"
它会起作用。
但如果我
tasklist /FI "CPUTIME gt 90"
没有。
我怎么知道时间格式代表90%? 还是80%? CPU使用时间和CPU使用百分比之间有什么关系?
I'm trying to use tasklist
to find out which process is consuming more than X percent of my CPU (to later kill it with taskkill
.)
How do I know what percent a time format represents?
The documentations says:
TASKLIST options
/FI filter
And one filter may be:
CPUTIME eq, ne, gt, lt, ge, le CPU time in the format: hh:mm:ss.
hh - number of hours,
mm - minutes, ss - seconds
If I try
tasklist /FI "CPUTIME gt 00:00:10"
it works.
But if I
tasklist /FI "CPUTIME gt 90"
it doesn't.
How can I know that time format represent 90%? Or 80%? What's the relationship between CPU usage time and the CPU usage percent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看起来没有一种简单的方法可以使用任务列表来执行此操作,因此我建议使用 VBscript 或其他脚本语言执行此操作,或者使用不同的方法。 如果您仅限于批处理文件,则可以使用 WMIC 命令获取正在运行的进程及其各自 CPUTime 的列表:
请注意,在我的测试中,这显示 wmipsrv.exe 具有 100% CPU,因为它在执行 WMI 查询时出现峰值。 您应该在脚本中考虑到这一点,否则您最终会尝试不断地终止 WMI 服务;)
参考:
http://waynes-world-it .blogspot.com/2008/09/useful-general-command-line-operations.html
http://technet.microsoft.com/en-us/library/bb742610.aspx
It doesn't look like there's an easy way to do this with tasklist, so I would suggest either doing this in VBscript or another scripting language, or using a different approach. If you're constrained to batch files then you could use the WMIC command to get the list of running processes with their respective CPUTime:
Note that this in my testing showed wmipsrv.exe as having 100% CPU, because it spiked while executing the WMI query. You should account for that in your script or you'll end up trying to kill the WMI service constantly ;)
Reference:
http://waynes-world-it.blogspot.com/2008/09/useful-general-command-line-operations.html
http://technet.microsoft.com/en-us/library/bb742610.aspx
任务列表不会告诉您该进程已经运行了多长时间。
它告诉您各个进程占用了多少 CPU 时间。
要获得百分比(这将是平均百分比),您需要知道进程已经运行了多长时间。
例如,您可以间隔 10 秒拍摄快照,减去时间,然后找到最接近数字 10 的进程 CPUTIME。(嗯,CPU 核心数的 10 倍?不确定......)
tasklist does not tell you how long the process has been running for.
It tells you how much CPU time the various processes have taken up.
To get a percentage (and that will be an average percentage) you need to know how long your process has been running for.
You could for instance take snapshots 10 seconds apart, subtract the times, then find the process CPUTIME which is nearest to the number 10. (Well 10 times the number of CPU cores? not sure...)
Tasklist 的 CPUTime 是对自进程启动以来使用了多少 CPU 时间(周期)的度量,因此将其转换为百分比,至少
,这就是我收集的:)
Tasklist's CPUTime is a measure of how much CPU time (cycles) have been used since the start of the process, so to convert that to a percent, it would be
At least, thats what I gather :)