I recently blogged about another method to obtain a process’ CPU usage via Command Line: Get CPU Usage of a Process from Command Line
Here’s a quick command line method for grabbing CPU usage of a process by process id, process name, or caption.
By Process ID
wmic path win32_perfformatteddata_perfproc_process where (IDProcess = '3488') get Name, Caption, PercentProcessorTime, IDProcess /format:list
By Process Name
wmic path win32_perfformatteddata_perfproc_process where (Name='iexplore') get Name, Caption, PercentProcessorTime, IDProcess /format:list
By Process Name (fuzzy)
wmic path win32_perfformatteddata_perfproc_process where (Name like '%iexp%') get Name, Caption, PercentProcessorTime, IDProcess /format:list
Any processes with CPU time over 50%
wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 50) get Name, Caption, PercentProcessorTime, IDProcess /format:list
26 Comments on "Get Process CPU Usage Using WMI"
Nice Job, I’ve been searching for this a long time and that one of CPU higher than is neat.
One question tough, do you know if I can search for a specific process with CPU time over 50%?.
Would be like the merger of 2 querys but I don’t know how to do it.
Hey thank you for the really fast answer.
The script works like a charm for me, but one last thing, could be modified so only look to one specific process?, for example the process iexplore
I guess this is the one
wmic path win32_perfformatteddata_perfproc_process where (PercentProcessorTime ^> 5 and Name ^ _Total and Name ^ Idle and Name ^ wmiprvse and name=’w3wp’) get Name, PercentProcessorTime, IDProcess /format:list
But at the end of the day there is a problem.
For some reason sometimes I get No Instance(s) Available, even when I can see in the task manager that the process is right about my mark, also I just get 100 or 0 instead of the real value which should be between 5 to 50
Thank you for your help
Are you doing this from the command line or in a batch file?
From the command line first then I will use a batch file
This, for example, will find processes with CPU time over 5% in this example. Replace 5 with the % you would like. Let me know if this works for you.
Note: This is one long line. Also, looks like there is a problem with this <code> or <pre> tag; It puts a space between the ^< ^> which it shouldn’t so if you copy and paste this it will give you an invalid query. Take the space out from between each of the ^< ^>.
I’m not sure I understand what you ask about searching for a specific process over 50%. Can you elaborate?
When you look at the results, you’ll see the CreatingProcessID in this now; Each tab runs under it’s own process ID. If you want to get details about the iexplore.exe process itself, you will want to query the PROCESS alias or win32_process path.
This will give you details on the actual iexplore.exe process.
You could try just logging some entries for the process to CSV format and reviewing them.
That will update every 10 seconds. To stop it, just:
logman stop w3wp_proc
Jump into c:perflogs and open up the CSV that will be in there for w3wp_proc. Maybe confirm if that counter isn’t broken by chance.
Rick Great blog here it has been very helpful.
Do you know how I would be able to automatically terminate the process that the query returns?
Setup your query to return the handles (I just use a quick filter ‘name’ instead of processor usage)
Returns the handles and if you know the handle…
You could implement that into a batch script.
So I’ve been trying to figure out how to determine process cpu utilization…and I cannot get an accurate number. When querying as you specified (as well as other sites), I cannot accurately get % CPU utilization of a process on a multi-processor OS. For example, if the process is using more than 25% of a 4-core server, the query only returns 100. Here is the query string: Select * from Win32_PerfFormattedData_PerfProc_Process where Name=’sqlservr’. Again, if the process is using a good portion of processor, it always says 100….I don’t understand why. Any thoughts?
I wish I had seen your response sooner. I am running into the same issue. Most of the processes are reporting either 0 or 100%.
It may be possible to modify this somewhat to get the desired results if it’s not what you’re looking for:
I had posted that earlier in May of this year.
Process(_Total)% Processor Timewill be N*100 (where N is the number of CPUs) because it adds up the CPU usage of each process,including the idle process.
Process(…)% Processor Timecan go up to N*100 (where N is the number of CPUs) because it adds up the CPU usage of the requested process across all the CPUs.
Processor(…)% Processor Timecan go up to 100 because it is the CPU usage of the requested CPU.
Processor(_Total)% ProcessorTime can go up to 100 because it is the average CPU usage across all CPUs
I think this gets beyond the scope of WMI/WMIC and would be better suited in either powershell or some other scripting/programming language possibly to be able to programmatically get the per-cpu/core usage stats. If someone knows, let me know then. =)
Thanks for the prompt and thorough response. I am actually writing my script in PowerShell. When I resolve the issue and if my results are applicable to this thread, I will post my solution. Thanks again.
Can you let me know how can i pull all processes with CPU and memory utilization remotely from a PC in column wise with WMIC?
You can use wmic /node:COMPUTERNAME to get to the remote computer.
when i run this
wmic path win32_perfformatteddata_perfproc_process where (IDProcess = ‘3488‘) get Name, Caption, PercentProcessorTime, IDProcess /format:list
it showing error as invalid query
I fixed the formatting of the command. If you look at the quotes, they are invalid (a formatting issue on WordPress side when I originally posted the article.
Try with the following:
Notice the difference:
Sorry about that, I’ve fixed all the commands in this article!
Now its working…
Thank you for responding soon.
same thing can i checked with service name instead of process id
Use something like the following to get the Process ID. You can then use that Process ID and construct the query above to get performance metrics.
A more complete example, using bits as the service name…