a program (process) may hang when it is running, need to monitor the program, and restart it when it hangs, to ensure that the program runs continuously.
there seems to be a daemon concept under Linux, and Windows is really simple, and batch processing can be done:
But here are a few commands to know
tasklist + find,ping.
tasklist is to list all processes, you can specify a process that lists only one user, and filter with the/FI parameter.
find/c can go to the results of tasklist to find the specified process name, and output the number.
There is another problem is how to set every time to detect whether the process is running, I use the ping command comes with the delay parameter-W, the IP address is set to an empty address,
for example, 0.0.0.1 so that the command will ping until it is n*w milliseconds to return (N and w are the values specified by parameter-N and-W, respectively).
The sample program is as follows: (Jf-svw.exe SIP forwarding process)
: RESTART
tasklist/fi "username eq Administrator" | find/c "Jf-svw.exe" > Temp.txt
set/p num= < Temp.txt
del/f temp.txt
Echo%num%
if "%num%" = = "0" start/d "C:\Program files\shell\svw\" Jf-svw.exe
ping-n 10-w 0.0.0.1 > Temp.txt
del/f temp.txt
Goto RESTART
Note The 1:goto statement is to set the monitor program to a dead loop.
NOTE 2: You can use the START/D path program to asynchronously call programs,
that is, the following statement is executed without waiting for the program to be specified, so you can set a fixed interval (n*w milliseconds) to monitor.
if calling program is a synchronous call, it waits for program execution to complete, so the delay is not
This article is from the "BBXWHN" blog, make sure to keep this source http://bbxwhn.blog.51cto.com/518597/1660695
Windows monitoring and restarting a process script