如何当它超过一定值检测过程中的CPU /内存使用情况,并杀了它? [英] How to detect a process cpu/memory usage and kill it when it exceeds a certain value?
问题描述
我学习C / C ++,我想知道是否有可能通过它的名字来检测过程,杀死它时,它的CPU /内存使用量超过一定值。我想一个preciate实际code任何帮助或只是指着我正确的方向。
i'm learning c/c++ and i'm wondering if it is possible to detect a process by it's name and kill it when it's cpu/memory usage exceed a certain value. I would apreciate any help with the actual code or just pointing me in the right direction.
推荐答案
有关Windows和C ++:
For Windows and c++:
查看 GetProcessMemoryInfo 。也有的 MSDN 的一个例子。
Check out GetProcessMemoryInfo. There's also an example at msdn.
的 GetProcessMemoryInfo()
功能将为您提供一个指针的 PROCESS_MEMORY_COUNTERS 结构里面包含了所有的内存使用信息。
The GetProcessMemoryInfo()
function will provide you a pointer to a PROCESS_MEMORY_COUNTERS struct which contains all of the memory usage information.
有关CPU使用率是比较难一点点,但下面的计算器的问题是有关的:<一href=\"http://stackoverflow.com/questions/18095994/getting-current-cpu-usage-in-c-windows-for-particular-process\">Getting特定工艺在C当前cpu使用率++ /窗口
For CPU usage it's a little bit more difficult but the following stackoverflow question is related to that: Getting current cpu usage in c++/windows for particular process
这篇关于如何当它超过一定值检测过程中的CPU /内存使用情况,并杀了它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!