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

相关文章:

  • 2021-12-05
  • 2021-11-06
  • 2022-01-29
  • 2021-11-17
  • 2022-02-03
  • 2021-10-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-07-26
  • 2021-05-04
相关资源
相似解决方案