使用 Java 检索 Window's 进程的 CPU 使用率 [英] Using Java to retrieve the CPU Usage for Window's Processes

查看:33
本文介绍了使用 Java 检索 Window's 进程的 CPU 使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个 Java 解决方案来查找 Windows 中正在运行的进程的 CPU 使用率.环顾网络后,似乎很少有关于 Java 解决方案的信息.请记住,我不是要查找 JVM 的 CPU 使用率,而是要查找当时在 Windows 中运行的任何进程.

I am looking for a Java solution to finding the CPU usage for a running process in Windows. After looking around the web, there seems to be little information on a solution in Java. Keep in mind, I am not looking to find the CPU usage for the JVM, but any process running in Windows at the time.

我能够通过使用 exec("tasklist.exe ... ") 来检索和解析进程信息来检索 Java 中的内存使用情况.虽然每个进程都有一个聚合的 CPU 周期计时器,但我没有看到 CPU 使用率列.

I am able to retrieve the memory usage in Java by using the exec("tasklist.exe ... ") to retrieve and parse process information. Although there is an aggregate CPU cycle timer for each process, I do not see a CPU usage column.

任何帮助将不胜感激.另外,如果可能的话,我想远离 C 库;但是,如果没有其他选择,通过这种方式的解决方案将是合适的.

Any help would be greatly appreciated. Also, if possible, I would like to stay away from C libraries; however, if there is no other alternative, a solution by that means would be appropriate.

非常感谢,

史蒂夫

推荐答案

如果 GPL 许可的 API 适合您,请尝试

If a GPL licensed API is fine for you, try out

SIGAR - 系统信息收集器和报告器

它允许访问您想要的信息(以及更多信息)并且在许多相关平台上都受支持

It allows access to the info you want (and much more) and is supported on many relevant platforms

这篇关于使用 Java 检索 Window's 进程的 CPU 使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆