Which process is reading this script

The next script is reading dllhost.exe amount of memory, however there are several dllhost.exe process in memory... so which one is taking the script? is it adding up all the memory all the process with the same name are using?

@echo off
setlocal
set LogFile=C:\Temp\dllhost.log
:loopPerf
set Usage=0
for /f "tokens=2 delims==" %%a in ('wmic.exe path Win32_PerfFormattedData_PerfProc_Process Where Name^='dllhost' get PercentProcessorTime /value ^| find.exe /i "PercentProcessorTime"') do set usage=%%a
if %usage% GEQ 80 (
	taskkill.exe /im dllhost.exe
	>>"%LogFile%" echo [%Date%][%Time%] Killed dllhost.
) else (
	echo abc
)
ping.exe -n 60 localhost >NUL
goto loopPerf

Open in new window

LVL 1
celticianAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
The script is not reading the amount of memory, it's reading the CPU time.
Anyway, if several processes are running, it'll get you one of the dllhost processes. The WMI instances  of the other processes will have a "#" followed by a number at the end.
Paste this directly into a command prompt:
wmic.exe path Win32_PerfFormattedData_PerfProc_Process Where "Name like 'dllhost%%'" get IDProcess,Name,PercentProcessorTime

Open in new window

To kill exactly the process that's eating up CPU cycles, you need something like this:
@echo off
setlocal enabledelayedexpansion
set Process=dllhost
set Limit=80
set LogFile=C:\Temp\dllhost.log
:loopPerf
set Usage=0
for /f "delims=" %%a in ('wmic.exe path Win32_PerfFormattedData_PerfProc_Process Where "Name='%Process%' or name like '%Process%#%%'" get PercentProcessorTime^,IDProcess /value ^| find.exe "="') do (
	for /f "tokens=1,2 delims==" %%w in ("%%a") do (
		set %%w=%%x
		if "%%w"=="PercentProcessorTime" (
			if !PercentProcessorTime! geq %Limit% (
				taskkill.exe /pid !IDProcess!
				>>"%LogFile%" echo [%Date%][%Time%] Killed %Process% with PID !IDProcess!.
			) else (
				echo usage for PID !IDProcess! at !PercentProcessorTime! at %time%
			)
		)
	)
)
ping.exe -n 61 localhost >NUL
goto loopPerf

Open in new window

You can test that by opening several instances of calc (and setting the process name accordingly) in the scientific view, and then letting one of them calculate the factorial of 87654.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
celticianAuthor Commented:
I tried exactly as you told me and works wonderfully well!!!

Now i need to move this script to the other old server we have with the same problem its a windows nt machine... ill post another question for this.

thanks for the script, its absolutely amazin and can be used for any process!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.