如何将任务列表的 CPU 时间转换为 CPU 使用百分比?

发布于 2024-07-08 10:24:35 字数 705 浏览 7 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

予囚 2024-07-15 10:24:35

看起来没有一种简单的方法可以使用任务列表来执行此操作,因此我建议使用 VBscript 或其他脚本语言执行此操作,或者使用不同的方法。 如果您仅限于批处理文件,则可以使用 WMIC 命令获取正在运行的进程及其各自 CPUTime 的列表:

C:\> wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime

Name                 PercentProcessorTime
Idle                 0
System               0
Smss                 0
csrss                0
winlogon             0
services             0
lsass                0

[...]

wmiprvse             100
wmic                 0
_Total               100

请注意,在我的测试中,这显示 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:

C:\> wmic path Win32_PerfFormattedData_PerfProc_Process get Name,PercentProcessorTime

Name                 PercentProcessorTime
Idle                 0
System               0
Smss                 0
csrss                0
winlogon             0
services             0
lsass                0

[...]

wmiprvse             100
wmic                 0
_Total               100

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

汹涌人海 2024-07-15 10:24:35

任务列表不会告诉您该进程已经运行了多长时间。
它告诉您各个进程占用了多少 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...)

☆獨立☆ 2024-07-15 10:24:35

Tasklist 的 CPUTime 是对自进程启动以来使用了多少 CPU 时间(周期)的度量,因此将其转换为百分比,至少

 (TotalProcessRuntime / CpuTime) / 100

,这就是我收集的:)

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

 (TotalProcessRuntime / CpuTime) / 100

At least, thats what I gather :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文