::@echo off
set "process_name=Rterm.exe"
::remoce .exe suffix if there is
set pn=%process_name:.exe=%
setlocal enableDelayedExpansion
set c=0
:: getting three snapshots of CPU usage of the given process
for /f skip^=2^ tokens^=3^ delims^=^" %%p in ('typeperf "\Process(%pn%)\%% Processor Time" -sc 3') do (
set /a counter=counter+1
::echo counter
for /f "tokens=1,2 delims=." %%a in ("%%p") do (
set "process_snapshot_!counter!=%%a%%b"
)
)
:: remove rem to see the cpu usage from the three snapshots
rem set process_snapshot_
:: if all three snapshots are less than 0000010 process will be killed
if 1%process_snapshot_1% LSS 10000010 if 1%process_snapshot_2% LSS 10000010 if 1%process_snapshot_3% LSS 10000010 (
tskill %pn%
echo %pn%
)
::pause