进程中有多个名字相同但路径不同的进程,用bat脚本分别监控,当退出进程时重新启动。
当进程存在时,每个10秒进行一次监控。有日志输出
@echo off
set _task = notepad.exe
set _svr = c:\windows\notepad.exe
set _des = start.bat
:checkService
for /f "tokens=5" %%n in ('qprocess.exe ^| find "%_task%" ') do (
if %%n==%_task% (goto checkMessage) else goto restartService
)
:restartService
echo %time%
echo ********程序开始启动********
echo 程序重新启动于 %time% ,请检查系统日志 >> restart_service.txt
echo start %_svr% > %_des%
echo exit >> %_des%
start %_des%
REM set /p=. set /p=. for /L %%i in (1 1 10) do set /p a=.nul
echo .
del %_des% /Q
echo ********程序启动完成********
goto checkService
:checkMessage
echo %time% 程序运行正常,5秒后继续检查..
ping localhost -n 5
goto checkService