Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kill process if more than X% Utilization

Status
Not open for further replies.

lardum

IS-IT--Management
Apr 26, 2000
462
SE
How can i kill a process that is using say more than 15%. The thing is that this process usually runs as 2 processes with the same name.
 
Hello lardum,

[1] Killing a process is easier than terminating a service. You can just retrieve a reference to it via querying the known property, .name in your case say, and then issue .terminate() method.
[2] For more than one instance running at the same time, you then retrieve the collection of the named processes. From each process in the collection, you determine the .pid of each individually. From pid you differentiate everyone instance of them.
[3] From each process (with the definite pid), you check out each instance of win32_PerfRawData_PerfProc_Process. From this reference, invoke the .PercentProcessorTime.
[4] For each percentprocesstime exceeding a given 15% say, you terminate that process with that pid.

This is the sketch you have to make. But, you know, sampling one time instance does not make much sense in this business. You might have to consider sampling quite a number, at least 2, with the average exceeding the limit to trigger the kill. Use wscript.sleep to get successive sampling points.

Hope the above can help you to identify the elements needed and to implementing the code.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top