Windows monitoring and restarting a process script

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.