Use the Windows command line tool tasklist and findstr, start and scheduled tasks to implement a process monitoring Solution

Source: Internet
Author: User

Windows is long-formed by the UI. However, the real powerful tool is still a command line tool.

Today, we will introduce a scheme to monitor whether a process works normally using the Windows command line tool tasklist, findstr, and start.

Tasklist: lists all processes currently executed by the system;

Findtr: Uses regular expressions to search for specified content in a string or text file;

Start: Start a target in a mode specified by some parameters

At the same time, the channel in the command line is also used. | this is a supper channel.

The solution is as follows:

Assume there is a service process called botserver, which allows a short period of unavailability, for example, 5 minutes;

The botserver automatically exits when an exception occurs;

To ensure that this process can continuously provide services, we create a bat batch processing file and add it to the system'sScheduled tasks, Set the execution cycle to 3 minutes;

In the BAT file, write the following content:

Tasklist | findstr/I botserver.exe

If errorlevel 1 start/B botserver.exe

 

Tasklist | findstr/I botserver.exeIs in the system process list, find botserver.exe

If errorlevel 1 start/B botserver.exeIf the search above does not match, start botserver.exe

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.