Kill long running task eating CPU

@ECHO OFF
SETLOCAL EnableDelayedExpansion
For /F "skip=1 tokens=* delims=" %%A IN ('tasklist /FI "imagename eq Task*" /v /nh') DO (

SET ln=%%A
SET sv=!ln:~0,30!
SET pd=!ln:~30,5!
SET tm=!ln:~148,8!
ECHO SERVICE: !sv! PID: !pd! RUN: !tm!


FOR /f "tokens=1,2,3 delims=:" %%a IN ("!tm!") DO (
SET hh=%%a
SET mm=%%b
SET ss=%%c
)

IF !hh! GTR 2 (
ECHO TASK RUNNING OVER 2 HOURS
ECHO %date% %time% ------------- >>C:\batchscripts\logs\TasksKilled.log
ECHO SERVICE: !sv! PID: !pd! RUNTIME: !tm! >>C:\batchscripts\logs\TasksKilled.log
TASKKILL /F /PID !pd! >>C:\batchscripts\logs\AMTasksKilled.log
)
)

NOTE: that task has to be eating time on the CPU, not just idle. CPUTIME is just that, the amount of time the process use the CPU

Comments :

0 comments to “Kill long running task eating CPU”