windows下利用批处理脚本监控程序


1.要监控的程序为使用cygwin环境编译的exe可执行文件hello.exe,源码如下:

#include <stdio.h>

#include <unistd.h>

void main(void)

{

  while(1)

  {

    printf("hello\n");

    sleep(1);

  }

}

2.以批处理形式启动hello.exe,那么启动hello.exe的批处理脚本如下:

@echo off

C:
chdir C:\cygwin64\bin
bash --login -i -c  "/cygdrive/c/Users/jello/Desktop/hello.exe"
pause

 

3.监控程序hello.exe的批处理脚本如下:

:RESTART
tasklist /FI "username eq jello" | find /C "hello.exe" > temp.txt
set /p num= < temp.txt
del /F temp.txt
echo %num%
if "%num%" == "0"        start /D "C:\Users\jello\Desktop\" start_hello.bat
ping -n 10 -w 2000 0.0.0.1 > temp.txt
del /F temp.txt

goto RESTART


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM